You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/07/29 10:43:51 UTC

[incubator-apisix] branch master updated: bugfix: run `apisix start` several times will start multi APISIX servers (#1913)

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/incubator-apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 333962a  bugfix: run `apisix start` several times will start multi APISIX servers (#1913)
333962a is described below

commit 333962a54bf51604fd46f392920850bf6c9ee5a6
Author: nic-chen <33...@users.noreply.github.com>
AuthorDate: Wed Jul 29 18:43:41 2020 +0800

    bugfix: run `apisix start` several times will start multi APISIX servers (#1913)
---
 .travis/linux_openresty_runner.sh | 17 +++++++++++++++++
 bin/apisix                        | 15 +++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/.travis/linux_openresty_runner.sh b/.travis/linux_openresty_runner.sh
index 4abb356..d5922c6 100755
--- a/.travis/linux_openresty_runner.sh
+++ b/.travis/linux_openresty_runner.sh
@@ -141,6 +141,23 @@ script() {
     ./bin/apisix init_etcd
     ./bin/apisix start
 
+    #start again  --> fial
+    res=`./bin/apisix start`
+    if [ "$res" != "APISIX is running..." ]; then
+        echo "failed: APISIX runs repeatedly"
+        exit 1
+    fi
+
+    #kill apisix
+    sudo kill -9 `ps aux | grep apisix | grep nginx | awk '{print $2}'`
+
+    #start -> ok
+    res=`./bin/apisix start`
+    if [ "$res" == "APISIX is running..." ]; then
+        echo "failed: shouldn't stop APISIX running after kill the old process."
+        exit 1
+    fi
+
     sleep 1
     cat logs/error.log
 
diff --git a/bin/apisix b/bin/apisix
index 3a2ee6c..762c326 100755
--- a/bin/apisix
+++ b/bin/apisix
@@ -854,6 +854,18 @@ local openresty_args = [[openresty  -p ]] .. apisix_home .. [[ -c ]]
                        .. apisix_home .. [[/conf/nginx.conf]]
 
 function _M.start(...)
+    -- check running
+    local pid_path = apisix_home .. "/logs/nginx.pid"
+    local pid, err = read_file(pid_path)
+    if pid then
+        local hd = io.popen("lsof -p " .. pid)
+        local res = hd:read("*a")
+        if res and res ~= "" then
+            print("APISIX is running...")
+            return nil
+        end
+    end
+
     init(...)
     init_etcd(...)
 
@@ -874,6 +886,9 @@ function _M.restart()
 end
 
 function _M.reload()
+    -- reinit nginx.conf
+    init()
+
     local test_cmd = openresty_args .. [[ -t -q ]]
     -- When success,
     -- On linux, os.execute returns 0,