Module: Unicorn::WorkerKiller

Defined in:
lib/unicorn/worker-killer-2.rb,
lib/unicorn/worker-killer-2/oom.rb,
lib/unicorn/worker-killer-2/max_requests.rb

Defined Under Namespace

Modules: MaxRequests, Oom

Class Method Summary collapse

Class Method Details

.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 5 QUIT signals, send 10 TERM signals. Finally, send a KILL signal. A single signal is sent per request.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/unicorn/worker-killer-2.rb', line 15

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

  @kill_attempts ||= 0
  @kill_attempts += 1

  sig = :QUIT
  sig = :TERM if @kill_attempts > 10
  sig = :KILL if @kill_attempts > 15

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

.nowObject



34
35
36
# File 'lib/unicorn/worker-killer-2.rb', line 34

def self.now
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

.randomize(integer) ⇒ Object



30
31
32
# File 'lib/unicorn/worker-killer-2.rb', line 30

def self.randomize(integer)
  Random.rand(integer.abs)
end