live: rewrite reboot operation

Add optional 'operation' parameter to _poweroff_oglive function.
Reuse _poweroff_oglive code before the busybox subprocess when rebooting
an ogLive client.
more_events v1.2.9
Jose M. Guisado 2023-05-04 12:56:26 +02:00
parent ef06618a8c
commit 66a464f7d0
1 changed files with 3 additions and 5 deletions

View File

@ -190,7 +190,7 @@ class OgLiveOperations:
with open(logfile, 'wb', 0) as f:
f.truncate(0)
def _poweroff_oglive(self):
def _poweroff_oglive(self, operation='poweroff'):
interface = os.getenv('DEVICE')
cmd_ethtool = shlex.split(f'ethtool -s {interface} wol g')
cmd_browser = shlex.split('pkill -9 browser')
@ -198,7 +198,7 @@ class OgLiveOperations:
busybox = 'busybox'
else:
busybox = shutil.which('busyboxOLD')
cmd_busybox = shlex.split(f'{busybox} poweroff')
cmd_busybox = shlex.split(f'{busybox} {operation}')
umount_all()
umount_cache()
@ -219,9 +219,7 @@ class OgLiveOperations:
def reboot(self):
logging.info('Rebooting client')
if os.path.exists('/scripts/oginit'):
cmd = f'source {ogClient.OG_PATH}etc/preinit/loadenviron.sh; ' \
f'{ogClient.OG_PATH}scripts/reboot'
subprocess.call([cmd], shell=True, executable=OG_SHELL)
self._poweroff_oglive(operation='reboot')
else:
subprocess.call(['/sbin/reboot'])