Skip to content

Commit

Permalink
Make max QUIT, max TERM, and sleep interval configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jclem committed Mar 8, 2013
1 parent 7f7cac1 commit 810da53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
11 changes: 11 additions & 0 deletions lib/unicorn/configuration.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 14 additions & 3 deletions lib/unicorn/worker_killer.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 810da53

Please sign in to comment.