diff options
Diffstat (limited to 'src/live')
-rw-r--r-- | src/live/ogOperations.py | 54 |
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() |