improved the rc lib, assuming the start function returns a pid
This commit is contained in:
parent
1f97e90066
commit
1c252126e8
11
lib/rc.lua
11
lib/rc.lua
@ -1,6 +1,7 @@
|
|||||||
local serial = require "serialization"
|
local serial = require "serialization"
|
||||||
|
|
||||||
local rc = {}
|
local rc = {}
|
||||||
|
rc.pids = {}
|
||||||
local service = {}
|
local service = {}
|
||||||
local cfg = {}
|
local cfg = {}
|
||||||
cfg.enabled = {}
|
cfg.enabled = {}
|
||||||
@ -37,12 +38,20 @@ end
|
|||||||
function rc.stop(name,...)
|
function rc.stop(name,...)
|
||||||
if not service[name] then return false, "service not found" end
|
if not service[name] then return false, "service not found" end
|
||||||
service[name].stop(...)
|
service[name].stop(...)
|
||||||
|
coroutine.yield()
|
||||||
|
if rc.pids[name] then
|
||||||
|
os.kill(rc.pids[name])
|
||||||
|
end
|
||||||
|
rc.pids[name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function rc.start(name,...)
|
function rc.start(name,...)
|
||||||
rc.load(name)
|
rc.load(name)
|
||||||
if not service[name] then return false, "service not found" end
|
if not service[name] then return false, "service not found" end
|
||||||
return service[name].start(...)
|
local rv = {service[name].start(...)}
|
||||||
|
if type(rv[1]) == "number" then
|
||||||
|
rc.pids[name] = rv[1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function rc.restart(name)
|
function rc.restart(name)
|
||||||
|
Loading…
Reference in New Issue
Block a user