diff --git a/lib/unicorn/configuration.rb b/lib/unicorn/configuration.rb new file mode 100644 index 0000000..8f48253 --- /dev/null +++ b/lib/unicorn/configuration.rb @@ -0,0 +1,11 @@ +module Unicorn::WorkerKiller + class Configuration + attr_accessor :max_quit, :max_term, :sleep_interval + + def initialize + self.max_quit = 10 + self.max_term = 15 + self.sleep_interval = 1 + end + end +end diff --git a/lib/unicorn/worker_killer.rb b/lib/unicorn/worker_killer.rb index 2bec0b0..e55dd28 100644 --- a/lib/unicorn/worker_killer.rb +++ b/lib/unicorn/worker_killer.rb @@ -1,3 +1,5 @@ +require 'unicorn/configuration' + module Unicorn::WorkerKiller # Self-destruction by sending the signals to myself. The process sometimes # doesn't terminate by SIGTERM, so this tries to send SIGQUIT and SIGKILL @@ -9,16 +11,16 @@ def self.kill_self(logger, start_time) while true i += 1 sig = :QUIT - if i > 10 # TODO configurable QUIT MAX + if i > configuration.max_quit sig = :TERM - elsif i > 15 # TODO configurable TERM MAX + elsif i > configuration.max_term sig = :KILL end logger.warn "#{self} send SIGTERM (pid: #{Process.pid}) alive: #{alive_sec} sec (trial #{i})" Process.kill sig, Process.pid - sleep 1 # TODO configurable sleep + sleep configuration.sleep_interval end end @@ -120,4 +122,13 @@ def process_client(client) end end end + + def self.configure + self.configuration ||= Configuration.new + yield(configuration) if block_given? + end + + class << self + attr_accessor :configuration + end end