Skip to content

Commit

Permalink
bugfix: run apisix start several times will start multi APISIX serv…
Browse files Browse the repository at this point in the history
…ers (#1913)
  • Loading branch information
nic-chen authored Jul 29, 2020
1 parent 552d700 commit 333962a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .travis/linux_openresty_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions bin/apisix
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)

Expand All @@ -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,
Expand Down

0 comments on commit 333962a

Please sign in to comment.