Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: run apisix start several times will start multi nginx processes #1913

Merged
merged 8 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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