attempt to add systemd-support for gentoo

This commit is contained in:
Fredrik Eriksson 2024-06-16 13:45:51 +02:00
parent cd33f98b8b
commit 5e5b77ed5e
Signed by: feffe
GPG Key ID: E6B5580B853D322B
2 changed files with 17 additions and 2 deletions

View File

@ -46,6 +46,12 @@ def init():
def fork_and_reboot(): def fork_and_reboot():
log = logging.getLogger(sau.LOGNAME) 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: try:
pid = os.fork() pid = os.fork()
if pid != 0: if pid != 0:

View File

@ -7,6 +7,7 @@ import sau.helpers
EIX_SYNC_PATH='/usr/bin/eix-sync' EIX_SYNC_PATH='/usr/bin/eix-sync'
RC_SERVICE_PATH='/sbin/rc-service' RC_SERVICE_PATH='/sbin/rc-service'
SYSTEMCTL='/usr/bin/systemctl'
EMERGE_PATH='/usr/bin/emerge' EMERGE_PATH='/usr/bin/emerge'
EQUERY_PATH='/usr/bin/equery' EQUERY_PATH='/usr/bin/equery'
EMAINT_PATH='/usr/sbin/emaint' EMAINT_PATH='/usr/sbin/emaint'
@ -20,6 +21,10 @@ slot_re = re.compile('^(\(~\))?([^\(]+)(\([^\)]+\))$')
def identify_service_from_bin(exe): def identify_service_from_bin(exe):
log = logging.getLogger(sau.LOGNAME) log = logging.getLogger(sau.LOGNAME)
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/(.*)') init_script_re = re.compile(r'/etc/init\.d/(.*)')
cmd = [ EQUERY_PATH, '-Cq', 'b', exe ] cmd = [ EQUERY_PATH, '-Cq', 'b', exe ]
@ -55,6 +60,10 @@ 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:
if f.readline() == 'systemd':
cmd = [ SYSTEMCTL, 'restart', service ]
else:
cmd = [ RC_SERVICE_PATH, service, 'restart' ] cmd = [ RC_SERVICE_PATH, service, 'restart' ]
ret, out, err = sau.helpers.exec_cmd(cmd) ret, out, err = sau.helpers.exec_cmd(cmd)