Created
July 31, 2014 20:32
-
-
Save softr8/6a650de7e505126cb082 to your computer and use it in GitHub Desktop.
Monitor puma workers
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 | |
MASTER_PID=`cat /home/deploy/app/shared/sockets/puma.state | grep pid | awk '{print $2}'` | |
PIDS=`ps auxwww | grep -v $MASTER_PID | grep [p]uma | awk '{print $2}'` | |
MAX_MEMORY=500000000 | |
for pid in $PIDS | |
do | |
MEM_USAGE=`ls -l /proc/$pid/as | awk '{print $5}'` | |
if [ $MEM_USAGE -gt $MAX_MEMORY ] | |
then | |
echo "Memory $MEM_USAGE exceeded $MAX_MEMORY killing $pid" | |
kill -s TERM $pid | |
else | |
echo "Everything ok, master PID: $MASTER_PID PID: $pid" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment