fix: ignore stale nginx.pid (#3416)

Fix #2948
Fix #3202

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
Co-authored-by: limiao <limiao02@qiyi.com>
This commit is contained in:
罗泽轩 2021-01-27 22:36:35 +08:00 committed by GitHub
parent b5374bb66c
commit 97a0956614
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 17 deletions

View File

@ -23,20 +23,6 @@
. ./.travis/apisix_cli_test/common.sh
# validate extra_lua_path
echo '
apisix:
extra_lua_path: ";"
' > conf/config.yaml
out=$(make init 2>&1 || true)
if ! echo "$out" | grep 'invalid extra_lua_path'; then
echo "failed: can't detect invalid extra_lua_path"
exit 1
fi
echo "passed: detect invalid extra_lua_path"
git checkout conf/config.yaml
# check 'Server: APISIX' is not in nginx.conf. We already added it in Lua code.
@ -1030,3 +1016,27 @@ if grep "failed to load plugin [3rd-party]" logs/error.log > /dev/null; then
exit 1
fi
echo "passed: 3rd-party plugin can be loaded"
# validate extra_lua_path
echo '
apisix:
extra_lua_path: ";"
' > conf/config.yaml
out=$(make init 2>&1 || true)
if ! echo "$out" | grep 'invalid extra_lua_path'; then
echo "failed: can't detect invalid extra_lua_path"
exit 1
fi
echo "passed: detect invalid extra_lua_path"
# 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
echo "failed: should ignore stale nginx.pid"
exit 1
fi
echo "pass: ignore stale nginx.pid"

View File

@ -426,13 +426,23 @@ local function start(env, ...)
-- check running
local pid_path = env.apisix_home .. "/logs/nginx.pid"
local pid = util.read_file(pid_path)
pid = tonumber(pid)
if pid then
local hd = popen("lsof -p " .. pid)
local lsof_cmd = "lsof -p " .. pid
local hd = popen(lsof_cmd)
local res = hd:read("*a")
if res and res ~= "" then
print("APISIX is running...")
if not (res and res == "") then
if not res then
print("failed to read the result of command: " .. lsof_cmd)
else
print("APISIX is running...")
end
return
end
print("nginx.pid exists but there's no corresponding process with pid ", pid,
", the file will be overwritten")
end
init(env, ...)