From 34fa78845941581449c63b75d760dd2e9163c5e6 Mon Sep 17 00:00:00 2001 From: spacewander Date: Thu, 29 Sep 2022 17:01:50 +0800 Subject: [PATCH] fix: prevent failing to start because of the conf server sock Signed-off-by: spacewander --- apisix/cli/ops.lua | 11 +++++++++++ t/cli/test_cmd.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua index c8cf6ab44e79..93bd17bf9417 100644 --- a/apisix/cli/ops.lua +++ b/apisix/cli/ops.lua @@ -784,6 +784,17 @@ local function start(env, ...) ", the file will be overwritten") end + -- start a new APISIX instance + + local conf_server_sock_path = env.apisix_home .. "/conf/config_listen.sock" + if pl_path.exists(conf_server_sock_path) then + -- remove stale sock (if exists) so that APISIX can start + local ok, err = os_remove(conf_server_sock_path) + if not ok then + util.die("failed to remove stale conf server sock file, error: ", err) + end + end + local parser = argparse() parser:argument("_", "Placeholder") parser:option("-c --config", "location of customized config.yaml") diff --git a/t/cli/test_cmd.sh b/t/cli/test_cmd.sh index bd8da86bb7b0..449069577ae7 100755 --- a/t/cli/test_cmd.sh +++ b/t/cli/test_cmd.sh @@ -21,6 +21,34 @@ git checkout conf/config.yaml +# remove stale conf server sock +touch conf/config_listen.sock +./bin/apisix start +sleep 0.5 +./bin/apisix stop +sleep 0.5 + +if [ -e conf/config_listen.sock ]; then + echo "failed: should remove stale conf server sock" + exit 1 +fi + +# don't remove stale conf server sock when APISIX is running +./bin/apisix start +sleep 0.5 +./bin/apisix start +sleep 0.5 + +if [ ! -e conf/config_listen.sock ]; then + echo "failed: should not remove stale conf server sock" + exit 1 +fi + +./bin/apisix stop +sleep 0.5 + +echo "passed: stale conf server sock removed" + # check restart with old nginx.pid exist echo "-1" > logs/nginx.pid out=$(./bin/apisix start 2>&1 || true)