Skip to content

Instantly share code, notes, and snippets.

@ralph
Forked from mattheworiordan/restart.sh
Last active July 17, 2020 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralph/b1b4023e0c03aa8c68f8219cd089de46 to your computer and use it in GitHub Desktop.
Save ralph/b1b4023e0c03aa8c68f8219cd089de46 to your computer and use it in GitHub Desktop.
Heroku scheduled restarts
#!/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