From 68908cf4e91a4eeb60e9296cb35211b9c40d9197 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 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua index 9a57cf4a91428..f2a6c9d17311b 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,20 @@ 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 err ~= nil then + if errno ~= errno_noproc then + print(err) + + return + end end print("nginx.pid exists but there's no corresponding process with pid ", pid,