7 ctl = UNIXSocket.open('/run/initctl')
8 ctl.puts(cmd.join(' '))
9 puts(ctl.readline.chomp)
14 # If we're not PID 1, parse & send commands to /run/initctl
18 when 'poweroff', 'restart', 'halt'
19 do_cmd(ARGV[0].to_sym)
21 do_cmd(ARGV.shift.to_sym, *ARGV)
23 map = { poweroff: 0x4321fedc, restart: 0x01234567, halt: 0xcdef0123 }
25 syscall(169, 0xfee1dead, 0x20112000, map[:poweroff])
27 puts('I know the following commands: poweroff, restart, halt, status, test')
38 # Needed to prevent respawning during a reboot...
42 # Here we do some process monitoring...
44 Signal.trap(:SIGCHLD) do
47 pid = Process.wait(-1, Process::WNOHANG)
48 key = $daemons.key(pid)
51 cmd = $daemonCmds[key]
53 $daemonCmds.delete(key)
55 # Respawn any processes that exit...
56 if key != 'openrc' && !$shuttingDown
74 print(' (error: %s)' % e)
81 puts('Starting %s...' % id)
92 puts('*** init-ng v1.0.0 starting...')
94 launch('openrc', %w[/sbin/rc sysinit])
95 Process.wait($daemons['openrc'])
97 launch('openrc', %w[/sbin/rc boot])
98 Process.wait($daemons['openrc'])
100 launch('openrc', %w[/sbin/rc default])
101 Process.wait($daemons['openrc'])
109 launch('openrc', %w[/sbin/rc reboot])
110 Process.wait($daemons['openrc'])
127 launch('agetty1', %w[/sbin/agetty tty1 --noclear --autologin root])
131 launch("agetty#{n}", %W[/sbin/agetty tty#{n} --noclear])
136 # This shows the one of the hazards of coding this in Ruby...
139 # LINUX_REBOOT_CMD_POWER_OFF == 0x4321FEDC
140 # LINUX_REBOOT_CMD_RESTART == 0x01234567
141 # LINUX_REBOOT_CMD_HALT == 0xCDEF0123
142 map = { poweroff: 0x4321fedc, restart: 0x01234567, halt: 0xcdef0123 }
144 # LINUX_REBOOT_MAGIC1 == 0xfee1dead
145 # LINUX_REBOOT_MAGIC2C == 0x20112000
146 syscall(169, 0xfee1dead, 0x20112000, map[cmd])
157 server = UNIXServer.open('/run/initctl')
158 rescue Errno::EADDRINUSE
159 File.delete('/run/initctl')
165 args = ctl.readline.chomp.split
166 cmd = args.shift.to_sym
168 when :poweroff, :restart, :halt
172 # ctl.puts($daemons[args.first] ? 'ok' : 'dead')
173 # This is NFG. It only shows on the main console, not on the socket, so
174 # you get nothing if you're ssh'ed in...
175 $daemons.each { |key, value| puts(key + ': ' + (value ? '[OK]' : '[!!]') + ' (' + value.to_s + ')') }