Created
April 19, 2012 13:48
-
-
Save w0rldart/2421072 to your computer and use it in GitHub Desktop.
Get site status with CURL and invoke services action (restart, stop)
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 | |
## ./services-action.sh restart => To restart all the services | |
## ./services-action.sh restart postfix => To restart specific service (postfix in this case) | |
initPath="/etc/init.d/" | |
services="apache2,mysql,amavis,postfix,courier-authdaemon,courier-imap,courier-imap-ssl,courier-pop,courier-pop-ssl" | |
export IFS="," | |
if [ $# -lt 1 ]; then | |
echo "Please enter an action to do" | |
exit 1 | |
fi | |
if [ ! "$2" == "" ]; then | |
$initPath$2 $1 | |
else | |
for service in $services; do | |
$initPath$service$input $1 | |
done | |
fi |
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/sh | |
## ./site-status.sh http://www.mysite.com => To get the site status code and if 200, do nothing, else ./services-action.sh restart | |
if [ $# -lt 1 ]; then | |
echo "Please enter the site you want to test" | |
exit 1; | |
fi | |
responseline=`curl -sL -w "%{http_code} %{url_effective}\\n" "$1" -o /dev/null` | |
export IFS=" " | |
i=0; | |
for code in $responseline; do | |
if [ $code == 200 ]; then | |
exit 0; | |
fi | |
if [ $code == 500 ]; then | |
/root/services-action.sh restart | |
fi | |
if [ $i == 0 ]; then | |
break; | |
fi | |
i=$(expr $i + 1); | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment