From ef06618a8c5b00680fb4f92e2d3b9f5dae1cbea7 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Thu, 4 May 2023 10:00:08 +0200 Subject: live: rewrite poweroff operation Replace legacy bash script /opt/opengnsys/client/scripts/poweroff with a Python native solution. Use subprocess module for any required external program when shutting down a client. ethtool is used to ensure WoL setting is correct before shutting down. ogLive does not properly use a init system so busybox is used when shutting down the system. In other live environments poweroff operation just calls /sbin/poweroff. --- src/live/ogOperations.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py index 56f0a75..a86db5c 100644 --- a/src/live/ogOperations.py +++ b/src/live/ogOperations.py @@ -190,12 +190,29 @@ class OgLiveOperations: with open(logfile, 'wb', 0) as f: f.truncate(0) + def _poweroff_oglive(self): + interface = os.getenv('DEVICE') + cmd_ethtool = shlex.split(f'ethtool -s {interface} wol g') + cmd_browser = shlex.split('pkill -9 browser') + if not shutil.which('busyboxOLD'): + busybox = 'busybox' + else: + busybox = shutil.which('busyboxOLD') + cmd_busybox = shlex.split(f'{busybox} poweroff') + + umount_all() + umount_cache() + if subprocess.run(cmd_ethtool).returncode != 0: + logging.error('Error running ethtool subprocess') + if subprocess.run(cmd_browser).returncode != 0: + logging.error('Error terminating ogBrowser process') + if subprocess.run(cmd_busybox) != 0: + logging.error('Error running "busybox poweroff" subprocess') + def poweroff(self): logging.info('Powering off client') if os.path.exists('/scripts/oginit'): - cmd = f'source {ogClient.OG_PATH}etc/preinit/loadenviron.sh; ' \ - f'{ogClient.OG_PATH}scripts/poweroff' - subprocess.call([cmd], shell=True, executable=OG_SHELL) + self._poweroff_oglive() else: subprocess.call(['/sbin/poweroff']) -- cgit v1.2.3-18-g5258