-
-
Save ralph/b1b4023e0c03aa8c68f8219cd089de46 to your computer and use it in GitHub Desktop.
Heroku scheduled restarts
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 | |
# Set up the Heroku scheduler to run this command every hour. | |
# Source: https://gist.github.com/ralph/b1b4023e0c03aa8c68f8219cd089de46 | |
utc_hour=`date -u +'%H' | sed 's/^0*//'` | |
modulo="${RESTART_EVERY_X_HOURS:-6}" | |
n=$(($utc_hour % $modulo)) | |
echo $n | |
echo "Current UTC hour is ${utc_hour}, restarting every ${modulo} hours." | |
if [[ "$n" -eq 0 ]]; then | |
echo "Restarting..." | |
curl -i -n -X DELETE https://api.heroku.com/apps/${HEROKU_APP_NAME}/dynos \ | |
-H "Authorization: Bearer ${HEROKU_TOKEN}" \ | |
-H "Content-Type: application/json" \ | |
-H "Accept: application/vnd.heroku+json; version=3" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment