From 1bdc0850d80c88ede08ebb45374c7a8687119f6b Mon Sep 17 00:00:00 2001 From: nic-chen Date: Mon, 27 Jul 2020 11:24:26 +0800 Subject: [PATCH 1/7] fix: multi nginx process can't update nginx.conf when reuseport is enabled --- bin/apisix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bin/apisix b/bin/apisix index 3a2ee6c9ce87..dd23922808fe 100755 --- a/bin/apisix +++ b/bin/apisix @@ -854,12 +854,21 @@ 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 + print("APISIX is running...") + return nil + end + init(...) init_etcd(...) local cmd = openresty_args -- print(cmd) os.execute(cmd) + end function _M.stop() @@ -874,6 +883,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, From 7e5733799c9e2ffb37193fd1597d4090350b7104 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Mon, 27 Jul 2020 16:32:45 +0800 Subject: [PATCH 2/7] add test case --- .travis/linux_openresty_runner.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis/linux_openresty_runner.sh b/.travis/linux_openresty_runner.sh index 4abb3565a0eb..3948beaeeabc 100755 --- a/.travis/linux_openresty_runner.sh +++ b/.travis/linux_openresty_runner.sh @@ -141,6 +141,13 @@ script() { ./bin/apisix init_etcd ./bin/apisix start + #start again + res=`./bin/apisix start` + if [ "$res" != "APISIX is running..." ]; then + echo "failed: APISIX runs repeatedly" + exit 1 + fi + sleep 1 cat logs/error.log From 5846ee88ecbd34adc58ea2336553d5910dd8eb1c Mon Sep 17 00:00:00 2001 From: nic-chen Date: Tue, 28 Jul 2020 23:14:29 +0800 Subject: [PATCH 3/7] determine whether the process exists --- .travis/linux_openresty_runner.sh | 12 +++++++++++- bin/apisix | 9 ++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.travis/linux_openresty_runner.sh b/.travis/linux_openresty_runner.sh index 3948beaeeabc..6e9319bc015f 100755 --- a/.travis/linux_openresty_runner.sh +++ b/.travis/linux_openresty_runner.sh @@ -141,13 +141,23 @@ script() { ./bin/apisix init_etcd ./bin/apisix start - #start again + #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 -s 9 `ps aux | grep apisix | awk '{print $2}'` + + #start -> ok + res=`./bin/apisix start` + if [ "$res" != "APISIX is running..." ]; then + echo "failed: APISIX runs repeatedly" + exit 1 + fi + sleep 1 cat logs/error.log diff --git a/bin/apisix b/bin/apisix index dd23922808fe..762c326a460c 100755 --- a/bin/apisix +++ b/bin/apisix @@ -858,8 +858,12 @@ function _M.start(...) local pid_path = apisix_home .. "/logs/nginx.pid" local pid, err = read_file(pid_path) if pid then - print("APISIX is running...") - return nil + 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(...) @@ -868,7 +872,6 @@ function _M.start(...) local cmd = openresty_args -- print(cmd) os.execute(cmd) - end function _M.stop() From 6c6e1e13afd4e957d4078b795d75763264a21933 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Tue, 28 Jul 2020 23:23:36 +0800 Subject: [PATCH 4/7] fix lint --- .travis/linux_openresty_runner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/linux_openresty_runner.sh b/.travis/linux_openresty_runner.sh index 6e9319bc015f..5d48893735eb 100755 --- a/.travis/linux_openresty_runner.sh +++ b/.travis/linux_openresty_runner.sh @@ -156,7 +156,7 @@ script() { if [ "$res" != "APISIX is running..." ]; then echo "failed: APISIX runs repeatedly" exit 1 - fi + fi sleep 1 cat logs/error.log From 26abeffab62ec56a631df0418060be54c5b6d890 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Tue, 28 Jul 2020 23:32:05 +0800 Subject: [PATCH 5/7] fix: kill: No such process --- .travis/linux_openresty_runner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/linux_openresty_runner.sh b/.travis/linux_openresty_runner.sh index 5d48893735eb..3439259d93be 100755 --- a/.travis/linux_openresty_runner.sh +++ b/.travis/linux_openresty_runner.sh @@ -149,7 +149,7 @@ script() { fi #kill apisix - sudo kill -s 9 `ps aux | grep apisix | awk '{print $2}'` + sudo kill -s 9 `ps aux | grep apisix | grep nginx | awk '{print $2}'` #start -> ok res=`./bin/apisix start` From 61ee31f6d99916d807fdce46022c76b7fa8949fa Mon Sep 17 00:00:00 2001 From: nic-chen Date: Tue, 28 Jul 2020 23:40:32 +0800 Subject: [PATCH 6/7] fix error --- .travis/linux_openresty_runner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/linux_openresty_runner.sh b/.travis/linux_openresty_runner.sh index 3439259d93be..2e7342c26c3b 100755 --- a/.travis/linux_openresty_runner.sh +++ b/.travis/linux_openresty_runner.sh @@ -149,7 +149,7 @@ script() { fi #kill apisix - sudo kill -s 9 `ps aux | grep apisix | grep nginx | awk '{print $2}'` + sudo kill -9 `ps aux | grep apisix | grep nginx | awk '{print $2}'` #start -> ok res=`./bin/apisix start` From 44c91a1617d90efa5f6907ad53223bfd687b14f4 Mon Sep 17 00:00:00 2001 From: nic-chen Date: Tue, 28 Jul 2020 23:49:32 +0800 Subject: [PATCH 7/7] fix error --- .travis/linux_openresty_runner.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis/linux_openresty_runner.sh b/.travis/linux_openresty_runner.sh index 2e7342c26c3b..d5922c6fcb3b 100755 --- a/.travis/linux_openresty_runner.sh +++ b/.travis/linux_openresty_runner.sh @@ -153,8 +153,8 @@ script() { #start -> ok res=`./bin/apisix start` - if [ "$res" != "APISIX is running..." ]; then - echo "failed: APISIX runs repeatedly" + if [ "$res" == "APISIX is running..." ]; then + echo "failed: shouldn't stop APISIX running after kill the old process." exit 1 fi