Created
April 27, 2017 00:03
-
-
Save sjmcgrath/83730cc947c87fca6a764c53fec9b741 to your computer and use it in GitHub Desktop.
Checks a URL for a response with retries and wait periods.
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 | |
NUMBER_OF_RETRIES={NUMBER_OF_RETRIES:-5} | |
WAIT_IN_SECONDS=${WAIT_IN_SECONDS:-30} | |
URL="${1:-127.0.0.1/index.php}" | |
URL_HASH="$( echo -n "${URL}" | cksum | sed 's/\s//g' )" | |
LOCK_FILE="/tmp/.page_ok.${URL_HASH}" | |
( | |
flock --nonblock 9 || exit 0 | |
wget --output-document=- --retry-connrefused --tries=${NUMBER_OF_RETRIES} --wait=${WAIT_IN_SECONDS} --quiet "${URL}" > /dev/null | |
) 9>"${LOCK_FILE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful for monitoring and restarting a service via crontab. (But don't do that, there are better options with Upstart and systemd.)
If you do though, you can do something like this in your crontab...