Created
October 28, 2017 16:45
-
-
Save maheshgawali/3e13bdf9afc46d357d53a3036d76464b to your computer and use it in GitHub Desktop.
restart apache gracefully
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 | |
check_process() { | |
echo "$ts: checking $1" | |
[ "$1" = "" ] && return 0 | |
[ `pgrep -n $1` ] && return 1 || return 0 | |
} | |
ts=`date +%T` | |
echo '$ts: stopping apache gracefully' | |
sudo service apache2 graceful-stop | |
while [ 1 ]; do | |
# timestamp | |
ts=`date +%T` | |
echo "$ts: begin checking... (5 sec interval)" | |
check_process "apache2" | |
[ $? -eq 0 ] && echo "$ts: not running, restarting..." && `sudo service apache2 restart > /dev/null` && break | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment