If you're running single-instance Mongrel, you may sometimes experience crashing if a process takes too long to execute. In the previous post, I talked about how I created an automated forum moderator. Problem is, it can sometimes crash if it has to archive too many spam posts with too many links at the same time. I won't be able to save its processing when it crashes, but next time it is hit by the cron, I can attempt to reboot the server by setting the 502 (bad gateway) error file to mongrel.php which contains the following code:
<? shell_exec('exec/mongrel.sh'); ?>
Futhermore, mongrel.sh contains a simple
#!/bin/sh
echo "Stopping any running ruby processes..."
/usr/bin/ruby /usr/bin/mongrel_rails stop -c /vservers/path/to/my/app
rm /vservers/path/to/my/app/log/mongrel.pid
killall -9 ruby
echo "Restarting Mongrel on port 4000.. Users may encounter 502 errors.."
/usr/bin/ruby /usr/bin/mongrel_rails start -c /vservers/path/to/my/app -e production -dp 4000