chore: Detect other NGINX and offer to kill (#25478)

In the `start-https.sh` script, detect if some other process is
listening on the ports we need, and if yes, inform of this, and offer to
kill and proceed.
This commit is contained in:
Shrikant Sharat Kandula 2023-07-19 16:39:11 +05:30 committed by GitHub
parent e73d066a9f
commit 3313cdadc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -340,6 +340,27 @@ if [[ -f $nginx_pid ]]; then
unset temp_nginx_conf
fi
remaining_listeners="$(
lsof -nP "-iTCP:$http_listen_port" -sTCP:LISTEN || true
lsof -nP "-iTCP:$https_listen_port" -sTCP:LISTEN || true
)"
if [[ -n $remaining_listeners ]]; then
echo $'\nThe following processes are listening on the ports we want to use:\n'"$remaining_listeners"$'\n' >&2
answer=
for attempt in 1 2 3; do
echo -n 'Kill and proceed? [y/n] ' >&2
read -rn1 answer
if [[ $answer == y ]]; then
(lsof -t "-iTCP:$http_listen_port" -sTCP:LISTEN | xargs kill) || true
(lsof -t "-iTCP:$https_listen_port" -sTCP:LISTEN | xargs kill) || true
break
elif [[ $answer == n || $attempt == 3 ]]; then
echo $'\nAborting.' >&2
exit 1
fi
done
fi
if [[ $run_as == nginx ]]; then
nginx -c "$nginx_dev_conf"
stop_cmd="nginx -c '$nginx_dev_conf' -s quit"