Created
June 20, 2019 04:27
-
-
Save matsubo/09b78a740851ebb181bf0b9d049859b6 to your computer and use it in GitHub Desktop.
Restart puma if physical memory usage is high.
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
*/15 * * * * /path/to/restart_if_high_memory.sh >> /tmp/restart_if_high_memory.log 2>&1 |
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 -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