Skip to content

Instantly share code, notes, and snippets.

@devopsmariocom
Last active August 29, 2015 14:16
Show Gist options
  • Save devopsmariocom/89c28fd9daf3595caa6a to your computer and use it in GitHub Desktop.
Save devopsmariocom/89c28fd9daf3595caa6a to your computer and use it in GitHub Desktop.
Check specified url and run specified command if url is not accesible
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'
#!/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