From e89793977e560f1ce29b4b9c3f76c979e01b20ab Mon Sep 17 00:00:00 2001 From: kwanhur Date: Sun, 8 May 2022 20:42:39 +0800 Subject: [PATCH] feat(ops): check process running with posix.signal insteadof lsof * remove shell command lsof dependency resolve #6977 * use signal SIGNONE(0) check process running or not Signed-off-by: kwanhur --- apisix/cli/ops.lua | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua index 9a57cf4a91428..cdc6508bec8d4 100644 --- a/apisix/cli/ops.lua +++ b/apisix/cli/ops.lua @@ -24,6 +24,7 @@ local profile = require("apisix.core.profile") local template = require("resty.template") local argparse = require("argparse") local pl_path = require("pl.path") +local signal = require("posix.signal") local stderr = io.stderr local ipairs = ipairs @@ -728,16 +729,19 @@ local function start(env, ...) local pid = util.read_file(pid_path) pid = tonumber(pid) if pid then - local lsof_cmd = "lsof -p " .. pid - local res, err = util.execute_cmd(lsof_cmd) - if not (res and res == "") then - if not res then - print(err) - else - print("APISIX is running...") - end + local signone = 0 + local errno_noproc = 3 + + local ok, err, errno = signal.kill(pid, signone) + if ok then + print("APISIX is running...") return + elseif errno ~= errno_noproc then + print(err) + + return + end end print("nginx.pid exists but there's no corresponding process with pid ", pid,