Class: Rpush::Daemon::SignalHandler
- Inherits:
-
Object
- Object
- Rpush::Daemon::SignalHandler
show all
- Extended by:
- Loggable
- Defined in:
- lib/rpush/daemon/signal_handler.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Methods included from Loggable
log_debug, log_error, log_info, log_warn
Class Attribute Details
.thread ⇒ Object
Returns the value of attribute thread.
7
8
9
|
# File 'lib/rpush/daemon/signal_handler.rb', line 7
def thread
@thread
end
|
Class Method Details
.handle_usr2 ⇒ Object
65
66
67
68
|
# File 'lib/rpush/daemon/signal_handler.rb', line 65
def self.handle_usr2
Rpush.logger.info('Received USR2 signal.')
AppRunner.debug
end
|
.start ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/rpush/daemon/signal_handler.rb', line 10
def self.start
return unless trap_signals?
read_io, @write_io = IO.pipe
start_handler(read_io)
%w(INT TERM HUP USR2).each do |signal|
Signal.trap(signal) { @write_io.puts(signal) }
end
end
|
.start_handler(read_io) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/rpush/daemon/signal_handler.rb', line 30
def self.start_handler(read_io)
@thread = Thread.new do
while readable_io = IO.select([read_io]) signal = readable_io.first[0].gets.strip
begin
case signal
when 'HUP'
handle_hup
when 'USR2'
handle_usr2
when 'INT', 'TERM'
Thread.new { Rpush::Daemon.shutdown }
break
when 'break'
break
else
Rpush.logger.error("Unhandled signal: #{signal}")
end
rescue StandardError => e
Rpush.logger.error("Error raised when handling signal '#{signal}'")
Rpush.logger.error(e)
end
end
end
end
|
.stop ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/rpush/daemon/signal_handler.rb', line 20
def self.stop
@write_io.puts('break') if @write_io
@thread.join if @thread
rescue StandardError => e
log_error(e)
reflect(:error, e)
ensure
@thread = nil
end
|
.trap_signals? ⇒ Boolean
70
71
72
|
# File 'lib/rpush/daemon/signal_handler.rb', line 70
def self.trap_signals?
!Rpush.config.embedded
end
|