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 12 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
24 changes: 23 additions & 1 deletion apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ local function start(env, ...)

local ok, err, err_no = signal.kill(pid, signone)
if ok then
print("APISIX is running...")
print("the old process is still running, the new one won't be started!")
hanqingwu marked this conversation as resolved.
Show resolved Hide resolved
return
-- no such process
elseif err_no ~= errno.ESRCH then
Expand Down Expand Up @@ -916,10 +916,32 @@ local function stop(env)
end


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

monkeyDluffy6017 marked this conversation as resolved.
Show resolved Hide resolved

local function wait_stop_finish(env, n)
for i = 1, n do
monkeyDluffy6017 marked this conversation as resolved.
Show resolved Hide resolved
-- check running
local pid_path = env.apisix_home .. "/logs/nginx.pid"
local pid = util.read_file(pid_path)
pid = tonumber(pid)
if not pid then
print("old apisix process has stopped")
hanqingwu marked this conversation as resolved.
Show resolved Hide resolved
return
else
sleep(1)
end
end
end
monkeyDluffy6017 marked this conversation as resolved.
Show resolved Hide resolved


local function restart(env)
-- test configuration
test(env)
stop(env)
wait_stop_finish(env, 3)
hanqingwu marked this conversation as resolved.
Show resolved Hide resolved
start(env)
end

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 process 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 process is still running"; then
echo "failed: should find APISIX running"
exit 1
fi
Expand Down
2 changes: 2 additions & 0 deletions t/cli/test_prometheus_stream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ make stop

echo "passed: prometheus works when both http & stream are enabled"

sleep 1 #wait for stop finish

echo "
apisix:
proxy_mode: stream
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 process is still running"); then
echo "failed: should restart failed when configuration invalid"
exit 1
fi
Expand Down
Loading