thuehlinger / daemons

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

customize which signals are sent to stop process #79

Closed philister closed 3 years ago

philister commented 3 years ago

For stop, user can now optionally set which signals are sent in which order. eg --signals_and_waits=TERM:10|KILL:20 is sending TERM and waiting 10s, then sending KILL and waiting 20s. Default ist TERM:20|KILL:20 as before

For example, this is useful in combination with delayed_job, where we override the start script "script/delayed_job" to give the workers more time to stop properly:

#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'

class Daemons::Application
  alias_method :original_stop, :stop
  def stop(no_wait = false)
    @signals_and_waits = [
      { sig: 'INT', wait:  20 },
      { sig: 'TERM', wait: 20 },
      { sig: 'KILL', wait: 20 }
    ]

    original_stop(no_wait)
  end
end

Delayed::Command.new(ARGV).daemonize