Skip to content

Commit

Permalink
fix: prevent failing to start because of the conf server sock (#8022)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander authored Sep 30, 2022
1 parent 30378f5 commit 68e3e0a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
28 changes: 28 additions & 0 deletions t/cli/test_cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68e3e0a

Please sign in to comment.