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

fix: apisix restart failed (#10495) #10696

Merged
merged 14 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 29 additions & 5 deletions apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,22 @@ local function cleanup(env)
end


local function sleep(n)
execute("sleep " .. tonumber(n))
end


local function check_running(env)
local pid_path = env.apisix_home .. "/logs/nginx.pid"
local pid = util.read_file(pid_path)
pid = tonumber(pid)
if not pid then
return false, nil
end
return true, pid
end


local function start(env, ...)
cleanup(env)

Expand All @@ -791,10 +807,18 @@ local function start(env, ...)
util.die(logs_path, " is not directory nor symbol link")
end

-- check running
local pid_path = env.apisix_home .. "/logs/nginx.pid"
local pid = util.read_file(pid_path)
pid = tonumber(pid)
-- check running and wait old apisix stop
local pid = nil
for i = 1, 30 do
local running
running, pid = check_running(env)
if not running then
break
else
sleep(0.1)
end
end

if pid then
if pid <= 0 then
print("invalid pid")
Expand All @@ -805,7 +829,7 @@ local function start(env, ...)

local ok, err, err_no = signal.kill(pid, signone)
if ok then
print("APISIX is running...")
print("the old APISIX is still running, the new one will not start")
return
-- no such process
elseif err_no ~= errno.ESRCH then
Expand Down
4 changes: 2 additions & 2 deletions t/cli/test_cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ git checkout conf/config.yaml
# check restart with old nginx.pid exist
echo "-1" > logs/nginx.pid
out=$(./bin/apisix start 2>&1 || true)
if echo "$out" | grep "APISIX is running"; then
if echo "$out" | grep "the old APISIX is still running"; then
rm logs/nginx.pid
echo "failed: should reject bad nginx.pid"
exit 1
Expand All @@ -50,7 +50,7 @@ echo "pass: no corresponding process"

# check running when run repeatedly
out=$(make run; make run || true)
if ! echo "$out" | grep "APISIX is running"; then
if ! echo "$out" | grep "the old APISIX is still running"; then
echo "failed: should find APISIX running"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion t/cli/test_validate_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ nginx_config:

# apisix restart
out=$(./bin/apisix restart 2>&1 || true)
if ! (echo "$out" | grep "\[emerg\] unknown directive \"notexist\"") && ! (echo "$out" | grep "APISIX is running"); then
if ! (echo "$out" | grep "\[emerg\] unknown directive \"notexist\"") && ! (echo "$out" | grep "the old APISIX is still running"); then
echo "failed: should restart failed when configuration invalid"
exit 1
fi
Expand Down
Loading