Ensure that certain processes are running when my Rails app loads

220 views Asked by At

I want to ensure that certain processes like Sunspot Solr search and delayed_job are running when my Rails 3 app initializes or loads.

I'm somewhat of a noob and from what I can tell, I could write a custom initializer or use a process monitoring framework like God or Monit.

Can someone please suggest the optimal path to take here?

3

There are 3 answers

0
Kevin Sylvestre On

If you are running a Rails application God is a very good option. If you are unfamiliar, Railscasts has a good screencast to get you started:

http://railscasts.com/episodes/130-monitoring-with-god

0
codatory On

You could write an initializer that checks, something like

raise ProcessNotRunning::MyProcess if `ps aux | grep 'processname' | grep -v grep | wc -l`.strip.zero?
0
Daniel Rikowski On

The problem with the initializer approach is that even if all your required processes are running at startup, there's is no guarantee they keep running the next few weeks or months your application is running.

Using a monitoring framework - both God and Monit are good solutions - you can be sure that even if one of your processes dies, it'll be restarted automatically. Also you can be notified when that happens, so you get notified early when problems are starting to happen.

In a nutshell: A monitoring framework will most likely be the better solution compared to any home-brewn solution.