Getting your mongrels to startup on boot is one of the last tricky things to do before your Rails setup is completely streamlined.
Using cron and a special @reboot option, the following steps will show you how to do this on a Fedora Core 5 linux system. (should work on similar systems as well)
About my setup—I deploy using a user account, let’s call it ‘foo’, which has a home directory of ’/home/foo’.
But we need to add the main @reboot cron entry as root.
# su to root: su # Now edit the root user's cron jobs: crontab -eAdd the following to the file:
@reboot /root/start_mongrels
Then save and exit—it should’ve installed your new cron job. (use “crontab -l” to confirm)
Now you need to create a file in /root/start_mongrels that will call a helper script that resides under your ‘foo’ (deployment user) account.
# Still as root: vi /root/start_mongrels
Paste in the following:
#!/bin/sh su - foo -c "cd /home/foo && ./restart_all.sh"
Then ensure the file is executable:
chmod 755 /root/start_mongrels
Now exit as root and return to being logged in as the ‘foo’ user. (whichever user you deploy your Rails apps as)
Create your restart_all.sh Script
Create a new file ’/home/foo/restart_all.sh’ with contents like:
#!/bin/sh # Restart the 'foojiggly' app pushd /u/apps/foojiggly/current mongrel_rails cluster::stop rm -rf log/*.pid mongrel_rails cluster::start # Restart the 'funster' app pushd /u/apps/foojiggly/current mongrel_rails cluster::stop rm -rf log/*.pid mongrel_rails cluster::start
Add as many entries as necessary. Newer versions of ‘mongrel_rails’ come with a ‘—clean’ option that you may want to use instead of the ‘rm -rf log/*.pid’ command.
Next, make sure the ‘restart_all.sh’ file is executable:chmod 755 /home/foo/restart_all.shNow be sure to do a test run to make sure it all works!
sudo /sbin/restart -r 0







