This is an automated email from the ASF dual-hosted git repository.

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 97a0956  fix: ignore stale nginx.pid (#3416)
97a0956 is described below

commit 97a095661497eb25df051a1274c331f4491ba1be
Author: 罗泽轩 <spacewander...@gmail.com>
AuthorDate: Wed Jan 27 22:36:35 2021 +0800

    fix: ignore stale nginx.pid (#3416)
    
    Fix #2948
    Fix #3202
    
    Signed-off-by: spacewander <spacewander...@gmail.com>
    Co-authored-by: limiao <limia...@qiyi.com>
---
 .travis/apisix_cli_test/test_main.sh | 38 +++++++++++++++++++++++-------------
 apisix/cli/ops.lua                   | 16 ++++++++++++---
 2 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/.travis/apisix_cli_test/test_main.sh 
b/.travis/apisix_cli_test/test_main.sh
index e422e82..1a2026d 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 4e03c5b..f9ebcbf 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, ...)

Reply via email to