Skip to content

Commit

Permalink
feat(ops): check process running with posix.signal insteadof lsof (ap…
Browse files Browse the repository at this point in the history
…ache#7006)

Signed-off-by: kwanhur <huang_hua2012@163.com>
Co-authored-by: 罗泽轩 <spacewanderlzx@gmail.com>
  • Loading branch information
2 people authored and Liu-Junlin committed May 20, 2022
1 parent 45f7ff9 commit 5252f32
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
23 changes: 15 additions & 8 deletions apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ 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 errno = require("posix.errno")

local stderr = io.stderr
local ipairs = ipairs
Expand Down Expand Up @@ -729,15 +731,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
if pid <= 0 then
print("invalid pid")
return
end

local signone = 0

local ok, err, err_no = signal.kill(pid, signone)
if ok then
print("APISIX is running...")
return
-- no such process
elseif err_no ~= errno.ESRCH then
print(err)
return
end

Expand Down
24 changes: 24 additions & 0 deletions t/cli/test_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,30 @@ fi
./bin/apisix stop
echo "pass: ignore stale nginx.pid"

# check no corresponding process
make run
oldpid=$(< logs/nginx.pid)
make stop
sleep 0.5
echo $oldpid > logs/nginx.pid
out=$(make run || true)
if ! echo "$out" | grep "nginx.pid exists but there's no corresponding process with pid"; then
echo "failed: should find no corresponding process"
exit 1
fi
make stop
echo "pass: no corresponding process"

# check running when run repeatedly
out=$(make run; make run || true)
if ! echo "$out" | grep "APISIX is running"; then
echo "failed: should find APISIX running"
exit 1
fi

make stop
echo "pass: check APISIX running"

# check the keepalive related parameter settings in the upstream
git checkout conf/config.yaml

Expand Down

0 comments on commit 5252f32

Please sign in to comment.