Class: Stalin::Killer

Inherits:
Object
  • Object
show all
Defined in:
lib/stalin/killer.rb

Overview

Kill a process by sending SIGQUIT several times, then SIGTERM, and finally SIGKILL.

Constant Summary collapse

MAX_GRACEFUL =

Number of cumulative shutdown tries before we escalate to abrupt-shutdown

10
MAX_ABRUPT =

Number of cumulative shutdown tries before we escalate to untrappable SIGKILL

15

Instance Method Summary collapse

Constructor Details

#initialize(pid, graceful, abrupt) ⇒ Killer

Returns a new instance of Killer.

Parameters:

  • pid (Integer)

    target process ID



10
11
12
13
14
15
# File 'lib/stalin/killer.rb', line 10

def initialize(pid, graceful, abrupt)
  @pid      = pid
  @graceful = graceful
  @abrupt   = abrupt
  @tries    = 0
end

Instance Method Details

#killSymbol

Try to kill the target process by sending it a shutdown signal.

Returns:

  • (Symbol)

    name of signal that we sent



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stalin/killer.rb', line 20

def kill
  case @tries
  when (0...MAX_GRACEFUL)
    sig = @graceful
  when (MAX_GRACEFUL...MAX_ABRUPT)
    sig = @abrupt
  else
    sig = :KILL
  end

  @tries += 1
  Process.kill(sig, @pid)
  sig
end