This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 68e3e0a55 fix: prevent failing to start because of the conf server
sock (#8022)
68e3e0a55 is described below
commit 68e3e0a558b4436ad90d33988a002706be68cec3
Author: 罗泽轩 <[email protected]>
AuthorDate: Fri Sep 30 13:23:59 2022 +0800
fix: prevent failing to start because of the conf server sock (#8022)
---
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 c8cf6ab44..93bd17bf9 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 bd8da86bb..449069577 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)