mirror of https://git.48k.eu/ogclient
live: refactor poweroff and reboot
- enable WoL - check for poweroff and reboot before checking for busybox. - call new shutdown methodmaster
parent
e003ff6d8c
commit
f1b1532f78
|
@ -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'):
|
||||
busybox = 'busybox '
|
||||
else:
|
||||
busybox = ''
|
||||
cmd_busybox = shlex.split(f'{busybox}{operation}')
|
||||
if shutil.which('browser') and subprocess.run(cmd_browser).returncode != 0:
|
||||
logging.error('Error terminating ogBrowser process')
|
||||
|
||||
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')
|
||||
|
||||
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_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()
|
||||
|
|
Loading…
Reference in New Issue