Skip to content

Instantly share code, notes, and snippets.

@maheshgawali
Created October 28, 2017 16:45
Show Gist options
  • Save maheshgawali/3e13bdf9afc46d357d53a3036d76464b to your computer and use it in GitHub Desktop.
Save maheshgawali/3e13bdf9afc46d357d53a3036d76464b to your computer and use it in GitHub Desktop.
restart apache gracefully
#!/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