Module: Unicorn::WorkerKiller

Defined in:
lib/unicorn/worker_killer.rb,
lib/unicorn/configuration.rb

Defined Under Namespace

Modules: MaxRequests, Oom Classes: Configuration

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



6
7
8
# File 'lib/unicorn/worker_killer.rb', line 6

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



107
108
109
110
# File 'lib/unicorn/worker_killer.rb', line 107

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration) if block_given?
end

.kill_self(logger, start_time) ⇒ Object

Kill the current process by telling it to send signals to itself. If the process isn’t killed after ‘configuration.max_quit` QUIT signals, send TERM signals until `configuration.max_term`. Finally, send a KILL signal. A single signal is sent per request.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unicorn/worker_killer.rb', line 14

def self.kill_self(logger, start_time)
  alive_sec = (Time.now - start_time).round
  worker_pid = Process.pid

  @@kill_attempts ||= 0
  @@kill_attempts += 1

  sig = :QUIT
  sig = :TERM if @@kill_attempts > configuration.max_quit
  sig = :KILL if @@kill_attempts > configuration.max_term

  logger.warn "#{self} send SIG#{sig} (pid: #{worker_pid}) alive: #{alive_sec} sec (trial #{@@kill_attempts})"
  Process.kill sig, worker_pid
end