Skip to content

Instantly share code, notes, and snippets.

@w0rldart
Created April 19, 2012 13:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w0rldart/2421072 to your computer and use it in GitHub Desktop.
Save w0rldart/2421072 to your computer and use it in GitHub Desktop.
Get site status with CURL and invoke services action (restart, stop)
#!/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
#!/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