Skip to content

Instantly share code, notes, and snippets.

@softr8
Created July 31, 2014 20:32
Show Gist options
  • Save softr8/6a650de7e505126cb082 to your computer and use it in GitHub Desktop.
Save softr8/6a650de7e505126cb082 to your computer and use it in GitHub Desktop.
Monitor puma workers
#!/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