diff --git a/.travis/linux_openresty_runner.sh b/.travis/linux_openresty_runner.sh index 4abb3565a0eb..d5922c6fcb3b 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 3a2ee6c9ce87..762c326a460c 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,