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: