From 5e5b77ed5e6f42c16b74b09907c369c490f66d71 Mon Sep 17 00:00:00 2001 From: Fredrik Eriksson Date: Sun, 16 Jun 2024 13:45:51 +0200 Subject: [PATCH] attempt to add systemd-support for gentoo --- bin/sau | 6 ++++++ sau/gentoo.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bin/sau b/bin/sau index d12ae1c..383d385 100755 --- a/bin/sau +++ b/bin/sau @@ -46,6 +46,12 @@ def init(): def fork_and_reboot(): log = logging.getLogger(sau.LOGNAME) + if os.path.exist('/proc/1/comm'): + with open('/proc/1/comm', 'r') as f: + if f.readline() == 'systemd': + os.execl('/usr/bin/systemctl', 'reboot') + log.error("Failed to execl?") + sys.exit(1) try: pid = os.fork() if pid != 0: diff --git a/sau/gentoo.py b/sau/gentoo.py index 14017aa..f1b8fe7 100644 --- a/sau/gentoo.py +++ b/sau/gentoo.py @@ -7,6 +7,7 @@ import sau.helpers EIX_SYNC_PATH='/usr/bin/eix-sync' RC_SERVICE_PATH='/sbin/rc-service' +SYSTEMCTL='/usr/bin/systemctl' EMERGE_PATH='/usr/bin/emerge' EQUERY_PATH='/usr/bin/equery' EMAINT_PATH='/usr/sbin/emaint' @@ -20,7 +21,11 @@ slot_re = re.compile('^(\(~\))?([^\(]+)(\([^\)]+\))$') def identify_service_from_bin(exe): log = logging.getLogger(sau.LOGNAME) - init_script_re = re.compile(r'/etc/init\.d/(.*)') + with open('/proc/1/comm', 'r') as f: + if f.readline() == 'systemd': + init_script_re = re.compile(r'[^/]*(.*)\.service$') + else: + init_script_re = re.compile(r'/etc/init\.d/(.*)') cmd = [ EQUERY_PATH, '-Cq', 'b', exe ] ret, out, err = sau.helpers.exec_cmd(cmd) @@ -55,7 +60,11 @@ def identify_service_from_bin(exe): def restart_service(service): log = logging.getLogger(sau.LOGNAME) - cmd = [ RC_SERVICE_PATH, service, 'restart' ] + with open('/proc/1/comm', 'r') as f: + if f.readline() == 'systemd': + cmd = [ SYSTEMCTL, 'restart', service ] + else: + cmd = [ RC_SERVICE_PATH, service, 'restart' ] ret, out, err = sau.helpers.exec_cmd(cmd) if ret != 0: