thuehlinger / daemons

Ruby daemons gem official repository
MIT License
648 stars 71 forks source link

:monitor & :multiple options don't work well together #7

Open thuehlinger opened 10 years ago

thuehlinger commented 10 years ago

When :monitor & :multiple are both set to true, and multiple daemon processes are started, only one monitor process gets started. And if the daemon processes crashes, only one of them gets restarted.

Source: http://stackoverflow.com/questions/14515250/daemons-do-not-get-restarted

sodabrew commented 10 years ago

The SO post has a great description of the issue. Do you think it's better to try and match the rbX.pid files with the monitors, or simply disable :multiple+:monitor with an error message?

sodabrew commented 10 years ago

What if the :multiple option can be an integer, or add a new option like :count or :num_workers?

adamruzicka commented 5 years ago

What is the status here? The issue is set to milestone 1.3.0 and latest version is 1.3.1, but the issue is still open.

jamesarosen commented 2 years ago

Related: :monitor + :multiple results in zombie processes.

@applications = (1..5).map do |i|
  Daemons.call(monitor: true, multiple: true, **some_other_options) do
    loop do
      if rand(5) == 0
        abort "Daemon #{i} stopping"
      else
        puts "Daemon #{i} still alive"
        sleep 1
      end
    end
  end
end

sleep 30
@applications.each(&:stop)

This will result in the Monitor restarting some of the daemons, but they won't be in @applications and will run forever. You can fix this by reaching through the Application to its ApplicationGroup:

@applications.each { |app| app.group.stop_all }