Ok, so I would like to create an action in Rails to restart itself. I did a little searching and found:
http://snippets.dzone.com/posts/show/5002
Which suggests
If you don't mind switching to mod_rails, you can restart your server by creating $RAILS_ROOT/tmp/restart.txt, which causes only the Rails instance you care about to restart.
Your PS command looks (cursorary glance) like it will kill all rails processes on your box. That's fine if you are the only Rails app on a machine, but if there's a few running as the same user or you are running as root you'll kill them all. Bad form!
This points it out for mongrel. There's the way you want to try.
Ok I found a fix... I changed how I start rails to:
mongrel_rails start -d
and now the following action will do it:
def restart
fork { exec "mongrel_rails restart" }
redirect_to "/server_maintenance"
end
As a caveat, the redirect_to will cause a failed load because the server will be down... however a reload after a pause will show that the restart was successful. This could be fixed by changing the restart to be done with AJAX, followed by a javascript reload... but I will leave that as an exercise to the reader.
In our consulting with startups running their sites on Rails, we used two methods for managing mongrel processes.
First, is a custom gem we wrote called mongrel_runit. This sets mongrels up as services in runit.
Second, we used god to monitor mongrel processes. This will work with mongrel_runit, or with 'normal' mongrel configurations.