Last active
August 29, 2015 14:16
-
-
Save devopsmariocom/89c28fd9daf3595caa6a to your computer and use it in GitHub Desktop.
Check specified url and run specified command if url is not accesible
This file contains hidden or 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
SHELL=/bin/sh | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
*/2 * * * * root /usr/local/bin/curl_watchdog.sh http://example.com8 'service name restart' |
This file contains hidden or 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 | |
HOST=$1 | |
RESTART_COMMAND=$2 | |
curl=/usr/bin/curl | |
# Check command | |
$curl -sSf $HOST > /dev/null 2>&1 | |
# Check return status | |
if [ "$?" -ne "0" ]; then | |
echo "Restarting using '$RESTART_COMMAND'" | |
eval ${RESTART_COMMAND} | |
exit 0 | |
fi | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment