X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=init;h=4e9382132bafb40917613198b91559fa31ee8fb5;hb=059e5fc9312a18f347ffcb40511e660125c030d8;hp=dc0f2ac18d55e6c268aa8b835c2c6b497c582418;hpb=96f2cf3474b5723cb42186f5950a008d3775ff2a;p=init-ng diff --git a/init b/init index dc0f2ac..4e93821 100755 --- a/init +++ b/init @@ -3,25 +3,26 @@ require 'socket' -def do_cmd(*cmd) - ctl = UNIXSocket.open('/run/initctl') - ctl.puts(cmd.join(' ')) - puts(ctl.readline.chomp) - exit -end - - # These are hashes - $daemons = {} $daemonCmds = {} # Needed to prevent respawning during a reboot... - $shuttingDown = false -# Here we do some process monitoring... +def launch(id, cmd) + puts('Starting %s...' % id) + pid = fork do + Process.setsid() + exec(*cmd) + end + $daemons[id] = pid + $daemonCmds[id] = cmd +end + + +# Here we do some process monitoring... Signal.trap(:SIGCHLD) do loop do begin @@ -47,17 +48,6 @@ Signal.trap(:SIGCHLD) do end -def launch(id, cmd) - puts('Starting %s...' % id) - pid = fork do - Process.setsid() - exec(*cmd) - end - $daemons[id] = pid - $daemonCmds[id] = cmd -end - - def init puts('*** init-ng v1.0.0 starting...') @@ -84,8 +74,15 @@ def shutdown end -# This shows the one of the hazards of coding this in Ruby... +def do_cmd(*cmd) + ctl = UNIXSocket.open('/run/initctl') + ctl.puts(cmd.join(' ')) + puts(ctl.readline.chomp) + exit +end + +# This shows the one of the hazards of coding this in Ruby... def sys_reboot(cmd) # LINUX_REBOOT_CMD_POWER_OFF == 0x4321FEDC # LINUX_REBOOT_CMD_RESTART == 0x01234567 @@ -164,6 +161,10 @@ loop do # you get nothing if you're ssh'ed in... $daemons.each { |key, value| puts(key + ': ' + (value ? '[OK]' : '[!!]') + ' (' + value.to_s + ')') } ctl.puts + when :start + puts('Received start msg from s-s-d: ' + args.to_s) + when :stop + puts('Received stop msg from s-s-d: ' + args.to_s) end end