Last active
September 3, 2022 22:45
-
-
Save fitorec/9068f30a2088465df9acc65fb7cb1688 to your computer and use it in GitHub Desktop.
Stopping service on specific port
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 | |
# | |
# | |
# PROBLEM: | |
# --------------------- | |
# If we run: | |
# pkill gunicorn | |
# We stop all gunicorn services, in this case to start gunicorn we only need to stop the parent | |
# process associated with the service that attends the port where gunicorn will be executed. | |
# | |
# The following script searches for said process (pid), if it exists it kills this process: | |
stop_unicorn_on_port() { | |
pid=$(lsof -w -t -i "TCP:${1}" | head -1) | |
if [ -z "${pid}" ]; then | |
echo "🦄 no service deamon on port ${1}" | |
else | |
kill -9 "${pid}" | |
echo "🦄 killed service deamon(${pid}) on port ${1}" | |
fi | |
} | |
# Example/Testing | |
stop_unicorn_on_port 5000 | |
stop_unicorn_on_port 5001 | |
stop_unicorn_on_port 5002 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment