Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ops): check process running with posix.signal insteadof lsof #7006

Merged
merged 15 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
tokers marked this conversation as resolved.
Show resolved Hide resolved

local ok, err, err_no = signal.kill(pid, signone)
kwanhur marked this conversation as resolved.
Show resolved Hide resolved
if ok then
print("APISIX is running...")
return
-- no such process
kwanhur marked this conversation as resolved.
Show resolved Hide resolved
elseif err_no ~= errno.ESRCH then
print(err)
return
end

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

# check operation not permitted
sudo make run
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace this test with a test that checks no such process? It seems we don't have test to cover it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

out=$(make run || true)
if ! echo "$out" | grep "Operation not permitted"; then
echo "failed: should find operation not permitted"
exit 1
fi
sudo make stop
echo "pass: operation not permitted"

# check running when run repeatedly
spacewander marked this conversation as resolved.
Show resolved Hide resolved
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