diff --git a/simpleinit.ini b/simpleinit.ini index 5d4c52d00c96dc17aea5afb91b18fa7b459e7af9..0ce29e2ebd697c32468e49b09f43d95f87df9eae 100644 --- a/simpleinit.ini +++ b/simpleinit.ini @@ -2,3 +2,12 @@ Runlevel=1 CmdStart=pulseaudio start CmdStop=pulseaudio stop + +[message] +Runlevel=2 +CmdStart= + say Subraum startet + sob subraum_startup +CmdStop= + say Subraum faehrt runter + sob subraum_shutdown diff --git a/simpleinit.py b/simpleinit.py index 5ff0949873384af6433439770aae214e9ed76be8..db1e9b1fef1abcd5fb06ca6fef01f13990e88dc7 100755 --- a/simpleinit.py +++ b/simpleinit.py @@ -18,8 +18,8 @@ for section in config.sections(): command = config[section] try: runlevel = int(command['Runlevel']) - start = command['CmdStart'] - stop = command['CmdStop'] + start = command['CmdStart'].splitlines() + stop = command['CmdStop'].splitlines() if runlevel not in runlevels: runlevels[runlevel] = list() runlevels[runlevel].append({ 'name': section, 'start': start, 'stop': stop }) @@ -31,10 +31,13 @@ old_level = 0 eins = Eins() -def emit_cmd(command_string): - print(f"Emitting cmd: {command_string}") - argv = shlex.split(command_string) - eins.emit_cmd(argv[0], *argv[1:]) +def emit_cmds(command_strings): + for command in command_strings: + if command == "": + continue + print(f"Emitting cmd: {command}") + argv = shlex.split(command) + eins.emit_cmd(argv[0], *argv[1:]) # This is a silent command, subinitd already describes the same command @eins.simple_cmd() @@ -48,13 +51,13 @@ def telinit2(new_level): if i in runlevels: for command in runlevels[i]: print(f"Starting {command['name']}") - emit_cmd(command['start']) + emit_cmds(command['start']) else: for i in reversed(range(new_level+1, old_level+1)): if i in runlevels: for command in runlevels[i]: print(f"Stopping {command['name']}") - emit_cmd(command['stop']) + emit_cmds(command['stop']) old_level = new_level