Daemons won't restart?
I am trying to run the same script in multiple daemons.
myapp.rb
as follows:
loop do
sleep 5
1 / 0 # crash it
end
my myapp_controller.rb
:
require 'rubygems'
require 'daemons'
options = {
:log_output => true,
:backtrace => true,
:monitor => true,
:multiple => true,
:log_dir => '/mnt/log/',
:hard_exit => true
}
Daemons.run(File.join(File.dirname(__FILE__), 'myapp.rb'), options)
When I run ruby myapp_controller.rb start
multiple times in a row, it creates many daemons as I expect. But after some time due to an error in the myapp.rb
daemons fail, and the monitor restarts only one and not all. So I end up with one running daemon.
Why? What am I doing wrong?
source to share
I was able to reproduce the behavior. This is not what you are doing wrong; it's a way of behaving daemons gem
.
Looking through the code for the gem daemon , it turns out that the option :multiple
doesn't work with the option :monitor
.
The parameter :monitor
works only when the daemon is started in one mode.
I created a bug report on the daemon project page , citing this question as the source.
More on reproducing the issue:
Several daemon processes are created when :multiple => true
. Each process has its own pid file in the format <scriptname>.rb<number>.pid
.
However, only one monitoring process is created (with one file <scriptname>.rb_monitor.pid
.)
Here is a list of processes started when the daemon process starts 3 times:
$ ps -fe | grep my_server
501 1758 1 0 12:25PM ?? 0:00.63 my_server.rb
501 1759 1 0 12:25PM ?? 0:00.43 my_server.rb_monitor
501 1764 1 0 12:25PM ?? 0:00.54 my_server.rb
501 1834 1 0 12:51PM ?? 0:00.31 my_server.rb
Files in pid / log folder:
$ ls /tmp/daemons-2013-01-25/
my_server.rb.log my_server.rb1.pid my_server.rb_monitor.pid
my_server.rb0.pid my_server.rb2.pid
source to share