2019-11-08 22:59:53 -05:00
|
|
|
if os.taskInfo(1) and os.pid() ~= 1 then
|
2019-11-08 22:23:18 -05:00
|
|
|
return false, "init already started"
|
|
|
|
end
|
2019-11-05 22:28:40 -05:00
|
|
|
os.setenv("PWD","/boot")
|
2019-11-08 22:23:18 -05:00
|
|
|
io.input("/dev/null")
|
|
|
|
io.output("/dev/syslog")
|
2019-11-19 05:38:22 -05:00
|
|
|
local f = io.open("/boot/cfg/hostname","rb")
|
|
|
|
local hostname = computer.address():sub(1,8)
|
|
|
|
if f then
|
|
|
|
hostname = f:read("*l")
|
|
|
|
f:close()
|
|
|
|
end
|
|
|
|
os.setenv("HOSTNAME",hostname)
|
|
|
|
syslog(string.format("Hostname set to %s",hostname))
|
2019-11-08 22:23:18 -05:00
|
|
|
local pids = {}
|
|
|
|
local function loadlist()
|
|
|
|
local f = io.open("/boot/cfg/init.txt","rb")
|
|
|
|
if not f then return false end
|
|
|
|
for line in f:read("*a"):gmatch("[^\r\n]+") do
|
|
|
|
pids[line] = -1
|
2019-11-03 16:55:04 -05:00
|
|
|
end
|
2019-11-08 22:23:18 -05:00
|
|
|
f:close()
|
2019-11-03 16:55:04 -05:00
|
|
|
end
|
2019-11-08 22:23:18 -05:00
|
|
|
loadlist()
|
2019-11-03 16:55:04 -05:00
|
|
|
while true do
|
2019-11-08 22:23:18 -05:00
|
|
|
for k,v in pairs(pids) do
|
|
|
|
if not os.taskInfo(v) then
|
2019-11-09 00:00:46 -05:00
|
|
|
syslog("Starting service "..k)
|
2019-11-08 22:23:18 -05:00
|
|
|
pids[k] = os.spawnfile("/boot/service/"..k)
|
|
|
|
end
|
|
|
|
end
|
2019-11-03 16:55:04 -05:00
|
|
|
coroutine.yield()
|
|
|
|
end
|