Created
January 26, 2022 15:21
-
-
Save justinyoo/045201b2c4280c818ca872af6284c720 to your computer and use it in GitHub Desktop.
This script kills the Azure Functions process for IntelliJ IDEA on Mac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Even after IntelliJ IDEA stops running the function app, | |
# the process is still alive. It only happens on IntelliJ IDEA on Mac. | |
# This script finds the Azure Functions process and kill it. | |
# | |
# You don't need this script if you use terminal or Visual Studio Code. | |
# You don't need this script if you run IntelliJ IDEA on Windows. | |
# | |
# Usage: ./kill-process.sh -p 7071 | |
# | |
set -e | |
# Usage function | |
function usage() { | |
cat <<USAGE | |
Usage: $0 [-p|--port-number <port number>] [-h|--help] | |
Options: | |
-p|--port-number: The port number to kill. | |
Default: 7071 | |
-h|--help: Show this message. | |
USAGE | |
exit 1 | |
} | |
# Set up arguments | |
port_number=7071 | |
if [[ $# -eq 0 ]]; then | |
port_number=7071 | |
fi | |
while [[ "$1" != "" ]]; do | |
case $1 in | |
-p | --port-number) | |
shift | |
port_number=$1 | |
;; | |
-h | --help) | |
usage | |
exit 1 | |
;; | |
*) | |
usage | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
if [[ $port_number == "" ]]; then | |
echo "Port number not set" | |
usage | |
exit 1 | |
fi | |
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Killing the process currently holding the port ..." | |
process_id=$(sudo lsof -nP -i4TCP:$port_number | grep LISTEN | awk '{print $2}') | |
if [[ $process_id != "" ]]; then | |
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Process ID: $process_id being killed ..." | |
sudo kill -9 $process_id | |
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Process ID: $process_id has been killed. You can now run the app." | |
else | |
echo "[$(date +"%Y-%m-%d %H:%M:%S")] No process found to kill. You can now run the app." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment