fix systemd test

This commit is contained in:
Fredrik Eriksson 2024-06-16 14:24:23 +02:00
parent 5e5b77ed5e
commit 6305fd053b
Signed by: feffe
GPG Key ID: E6B5580B853D322B
2 changed files with 3 additions and 3 deletions

View File

@ -48,7 +48,7 @@ def fork_and_reboot():
log = logging.getLogger(sau.LOGNAME) log = logging.getLogger(sau.LOGNAME)
if os.path.exist('/proc/1/comm'): if os.path.exist('/proc/1/comm'):
with open('/proc/1/comm', 'r') as f: with open('/proc/1/comm', 'r') as f:
if f.readline() == 'systemd': if f.readline().strip() == 'systemd':
os.execl('/usr/bin/systemctl', 'reboot') os.execl('/usr/bin/systemctl', 'reboot')
log.error("Failed to execl?") log.error("Failed to execl?")
sys.exit(1) sys.exit(1)

View File

@ -22,7 +22,7 @@ def identify_service_from_bin(exe):
log = logging.getLogger(sau.LOGNAME) log = logging.getLogger(sau.LOGNAME)
with open('/proc/1/comm', 'r') as f: with open('/proc/1/comm', 'r') as f:
if f.readline() == 'systemd': if f.readline().strip() == 'systemd':
init_script_re = re.compile(r'[^/]*(.*)\.service$') init_script_re = re.compile(r'[^/]*(.*)\.service$')
else: else:
init_script_re = re.compile(r'/etc/init\.d/(.*)') init_script_re = re.compile(r'/etc/init\.d/(.*)')
@ -61,7 +61,7 @@ def identify_service_from_bin(exe):
def restart_service(service): def restart_service(service):
log = logging.getLogger(sau.LOGNAME) log = logging.getLogger(sau.LOGNAME)
with open('/proc/1/comm', 'r') as f: with open('/proc/1/comm', 'r') as f:
if f.readline() == 'systemd': if f.readline().strip() == 'systemd':
cmd = [ SYSTEMCTL, 'restart', service ] cmd = [ SYSTEMCTL, 'restart', service ]
else: else:
cmd = [ RC_SERVICE_PATH, service, 'restart' ] cmd = [ RC_SERVICE_PATH, service, 'restart' ]