diff --git a/.travis/apisix_cli_test/test_main.sh b/.travis/apisix_cli_test/test_main.sh index e422e82e..1a2026d3 100755 --- a/.travis/apisix_cli_test/test_main.sh +++ b/.travis/apisix_cli_test/test_main.sh @@ -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" diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua index 4e03c5bf..f9ebcbf9 100644 --- a/apisix/cli/ops.lua +++ b/apisix/cli/ops.lua @@ -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, ...)