Skip to content

Instantly share code, notes, and snippets.

@matsubo
Created June 20, 2019 04:27
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 matsubo/09b78a740851ebb181bf0b9d049859b6 to your computer and use it in GitHub Desktop.
Save matsubo/09b78a740851ebb181bf0b9d049859b6 to your computer and use it in GitHub Desktop.
Restart puma if physical memory usage is high.
*/15 * * * * /path/to/restart_if_high_memory.sh >> /tmp/restart_if_high_memory.log 2>&1
#!/bin/bash -x
set -e
HOME=/path/to/app
cd $HOME
# returns 1 if physical memoryusage is higher than 80%
usage=`free -m | sed -n 2p | awk '{ printf("%d", ($3/$2)/0.8) }'`
if [ $usage -ge 1 ]; then
cd path/to/current && kill -USR2 `cat tmp/pids/puma.pid`
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment