Skip to content

Commit

Permalink
feat(ops): check process running with posix.signal insteadof lsof
Browse files Browse the repository at this point in the history
* remove shell command lsof dependency resolve #6977
* use signal SIGNONE(0) check process running or not

Signed-off-by: kwanhur <huang_hua2012@163.com>
  • Loading branch information
kwanhur committed May 8, 2022
1 parent 0d1280c commit e897939
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e897939

Please sign in to comment.