Class: Uc::Unicorn::GradualShutdown
- Inherits:
-
Object
- Object
- Uc::Unicorn::GradualShutdown
show all
- Includes:
- Logger, Helper
- Defined in:
- lib/uc/unicorn/gradual_shutdown.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helper
#first_worker?, #last_worker?, #old_pid, #restart?
Methods included from Logger
#event_queue, event_stream, #event_stream, logger, #logger, stderr, #stderr
Constructor Details
Returns a new instance of GradualShutdown.
14
15
16
17
|
# File 'lib/uc/unicorn/gradual_shutdown.rb', line 14
def initialize(server, worker)
@server = server
@worker = worker
end
|
Instance Attribute Details
#server ⇒ Object
Returns the value of attribute server.
12
13
14
|
# File 'lib/uc/unicorn/gradual_shutdown.rb', line 12
def server
@server
end
|
#worker ⇒ Object
Returns the value of attribute worker.
12
13
14
|
# File 'lib/uc/unicorn/gradual_shutdown.rb', line 12
def worker
@worker
end
|
Instance Method Details
#id ⇒ Object
49
50
51
|
# File 'lib/uc/unicorn/gradual_shutdown.rb', line 49
def id
@id ||= (worker.nr + 1)
end
|
#log_kill_error(e) ⇒ Object
44
45
46
47
|
# File 'lib/uc/unicorn/gradual_shutdown.rb', line 44
def log_kill_error(e)
stderr.info "error sending kill signal #{id}| #{e.class} #{e.message}"
event_stream.warn "error while stopping worker #{worker.nr + 1}, #{e.class}"
end
|
#run ⇒ Object
19
20
21
22
23
|
# File 'lib/uc/unicorn/gradual_shutdown.rb', line 19
def run
return if not (server && worker)
return if not restart?
shutdown_old_master
end
|
#send_signal ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/uc/unicorn/gradual_shutdown.rb', line 36
def send_signal
Process.kill(sig, File.read(old_pid).to_i)
return true
rescue => e
log_kill_error e
return false
end
|
#shutdown_old_master ⇒ Object
25
26
27
28
29
30
|
# File 'lib/uc/unicorn/gradual_shutdown.rb', line 25
def shutdown_old_master
event_stream.debug "stopping old worker #{id}"
if send_signal
event_stream.debug "stopped old worker #{id}"
end
end
|
#sig ⇒ Object
32
33
34
|
# File 'lib/uc/unicorn/gradual_shutdown.rb', line 32
def sig
(worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
end
|