Make sure certain processes are running when the Rails application loads.

I want certain processes, such as Sunspot Solr searches and delayed_job, to be executed when my Rails 3 application is initialized or loaded.

I am a little noob, and from what I can say, I could write a custom initializer or use a process monitoring infrastructure such as God or Monit.

Can anyone suggest an optimal way for this?

+4
source share
3 answers

If you are using a Rails application, this 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

+1
source

You can write an initializer that checks, something like

raise ProcessNotRunning::MyProcess if `ps aux | grep 'processname' | grep -v grep | wc -l`.strip.zero? 
+1
source

The problem with the initializer approach is that even if all your required processes start at startup, there is no guarantee that they will continue to work for the next few weeks or months when your application is running.

Using a monitoring structure - both God and Monitus - are good decisions - you can be sure that even if one of your processes dies, it will be restarted automatically. You can also be notified when this happens, so you will receive a notification sooner when problems begin.

In short: a monitoring framework is likely to be a better solution than any home marriage solution.

+1
source

Source: https://habr.com/ru/post/1341544/


All Articles