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: prevent failing to start because of the conf server sock #8022

Merged
merged 1 commit into from
Sep 30, 2022
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
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