Skip to content

Instantly share code, notes, and snippets.

@lackac
Created October 22, 2009 16:14
Show Gist options
  • Save lackac/216060 to your computer and use it in GitHub Desktop.
Save lackac/216060 to your computer and use it in GitHub Desktop.
A primitive way to ensure that your Passenger processes don't eat up your machine completely. It will kill any Rack app process that starts to eat more than 300MB RAM. I used this to find a leak in a Sinatra application.
#!/bin/bash
while :; do
stats=$(passenger-memory-stats | grep Rack)
if [ "$stats" != "" ]; then
echo $stats
echo $stats | egrep --color=always 'MB ([12][0-9]|[3-9])..\.. MB'
pid=$(echo $stats | egrep 'MB ([12][0-9]|[3-9])..\.. MB' | awk '{ print $1 }')
if [ "$pid" != "" ]; then
ps aux | grep $pid
kill $pid && echo "$pid killed."
fi
echo "---"
fi
sleep 0.5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment