From 3313cdadc07c4e7eeaf63e9a60614d73d208307f Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Wed, 19 Jul 2023 16:39:11 +0530 Subject: [PATCH] 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. --- app/client/start-https.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/client/start-https.sh b/app/client/start-https.sh index 9c0546535e..4904fa5de9 100755 --- a/app/client/start-https.sh +++ b/app/client/start-https.sh @@ -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"