From 1c252126e8b853d9f8661654a3e95ff2ad938ff9 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Tue, 24 Mar 2020 16:27:51 +1100 Subject: [PATCH] improved the rc lib, assuming the start function returns a pid --- lib/rc.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rc.lua b/lib/rc.lua index ab73ded..e9ae788 100644 --- a/lib/rc.lua +++ b/lib/rc.lua @@ -1,6 +1,7 @@ local serial = require "serialization" local rc = {} +rc.pids = {} local service = {} local cfg = {} cfg.enabled = {} @@ -37,12 +38,20 @@ end function rc.stop(name,...) if not service[name] then return false, "service not found" end service[name].stop(...) + coroutine.yield() + if rc.pids[name] then + os.kill(rc.pids[name]) + end + rc.pids[name] = nil end function rc.start(name,...) rc.load(name) 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 function rc.restart(name)