Skip to content

Commit

Permalink
(temp) fix power_off
Browse files Browse the repository at this point in the history
remove shutdown service
  • Loading branch information
Ptosiek committed Sep 27, 2023
1 parent cbf101a commit d9ce697
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
15 changes: 11 additions & 4 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from logger import CustomRotatingFileHandler, app_logger
from modules.helper.setting import Setting
from modules.button_config import Button_Config
from modules.utils.cmd import exec_cmd, exec_cmd_return_value
from modules.utils.cmd import exec_cmd, exec_cmd_return_value, is_running_as_service
from modules.utils.timer import Timer


Expand Down Expand Up @@ -1003,10 +1003,17 @@ async def quit(self):
self.loop.close()

def poweroff(self):
# TODO
# should be replaced by quit() with power_off option
# keep the logic for now but remove the shutdown service eg:
# if we are running through a service, stop it and issue power-off command (on rasp-pi only)

# this returns 0 if active

if is_running_as_service():
exec_cmd(["sudo", "systemctl", "stop", "pizero_bikecomputer"])
if self.G_IS_RASPI:
exec_cmd(
["sudo", "systemctl", "start", "pizero_bikecomputer_shutdown.service"]
)
exec_cmd(["sudo", "poweroff"])

def reboot(self):
if self.G_IS_RASPI:
Expand Down
10 changes: 9 additions & 1 deletion modules/utils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from logger import app_logger


# still return returncode
def exec_cmd(cmd, cmd_print=True):
if cmd_print:
app_logger.info(cmd)
try:
subprocess.run(cmd)
return subprocess.run(cmd).returncode
except Exception: # noqa
app_logger.exception(f"Failed executing {cmd}")

Expand All @@ -25,3 +26,10 @@ def exec_cmd_return_value(cmd, cmd_print=True):
return string
except Exception: # noqa
app_logger.exception(f"Failed executing {cmd}")


# TODO we might want to compare pid, because it might be running as a service AND manually
def is_running_as_service():
return not exec_cmd(
["sudo", "systemctl", "is-active", "--quiet", "pizero_bikecomputer"]
)

This file was deleted.

6 changes: 0 additions & 6 deletions scripts/install/usr/local/bin/pizero_bikecomputer_shutdown

This file was deleted.

0 comments on commit d9ce697

Please sign in to comment.