summaryrefslogtreecommitdiffstats
path: root/src/live/ogOperations.py
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-10-01 21:53:57 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-10-01 22:12:17 +0200
commitf1b1532f78e63ebd8e09735b413ec1ad8b8ad658 (patch)
tree4fa8d2c1dc1daaa3f222a87137372d91bad3ca81 /src/live/ogOperations.py
parente003ff6d8c08848d2e6fe3aae805b451ee8ef89c (diff)
live: refactor poweroff and reboot
- enable WoL - check for poweroff and reboot before checking for busybox. - call new shutdown method
Diffstat (limited to 'src/live/ogOperations.py')
-rw-r--r--src/live/ogOperations.py54
1 files changed, 40 insertions, 14 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 2451c9b..74e4c09 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -342,32 +342,58 @@ class OgLiveOperations:
with open(logfile, 'wb', 0) as f:
f.truncate(0)
- def _poweroff_oglive(self, operation='poweroff'):
- interface = get_ethernet_interface()
+ def _enable_wol(self, interface):
cmd_ethtool = shlex.split(f'ethtool -s {interface} wol g')
+ if subprocess.run(cmd_ethtool).returncode != 0:
+ logging.error('Error running ethtool subprocess')
+
+ def _shutdown(self, interface, cmd):
cmd_browser = shlex.split('pkill -9 browser')
- if shutil.which('busybox'):
+ if shutil.which('browser') and subprocess.run(cmd_browser).returncode != 0:
+ logging.error('Error terminating ogBrowser process')
+
+ umount_all()
+ umount_cache()
+
+ ret = subprocess.run(cmd)
+ if ret.returncode != 0:
+ logging.error(f'Error running {cmd} subprocess')
+
+ def _poweroff_oglive(self, interface):
+ self._enable_wol(interface)
+ if shutil.which('poweroff'):
+ busybox = ''
+ elif shutil.which('busybox'):
busybox = 'busybox '
else:
+ logging.warning('No poweroff binary found')
busybox = ''
- cmd_busybox = shlex.split(f'{busybox}{operation}')
- umount_all()
- umount_cache()
- if subprocess.run(cmd_ethtool).returncode != 0:
- logging.error('Error running ethtool subprocess')
- if shutil.which('browser') and 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')
+ cmd_poweroff = shlex.split(f'{busybox}poweroff')
+ self._shutdown(interface, cmd_poweroff)
def poweroff(self):
logging.info('Powering off client')
- self._poweroff_oglive()
+ interface = get_ethernet_interface()
+ self._poweroff_oglive(interface)
+
+ def _reboot_oglive(self, interface):
+ self._enable_wol(interface)
+ if shutil.which('reboot'):
+ busybox = ''
+ elif shutil.which('busybox'):
+ busybox = 'busybox '
+ else:
+ logging.warning('No reboot binary found')
+ busybox = ''
+
+ cmd_reboot = shlex.split(f'{busybox}reboot')
+ self._shutdown(interface, cmd_reboot)
def reboot(self):
logging.info('Rebooting client')
- self._poweroff_oglive(operation='reboot')
+ interface = get_ethernet_interface()
+ self._reboot_oglive(interface)
def shellrun(self, request, ogRest):
cmd = request.getrun()