Class: UnicornHorn::SelfPipeDaemon
- Inherits:
-
Object
- Object
- UnicornHorn::SelfPipeDaemon
- Extended by:
- Configurer
- Defined in:
- lib/unicorn_horn/self_pipe_daemon.rb
Direct Known Subclasses
Constant Summary collapse
- SELF_PIPE =
[]
- SIG_QUEUE =
[]
Instance Method Summary collapse
- #forget ⇒ Object
-
#initialize ⇒ SelfPipeDaemon
constructor
A new instance of SelfPipeDaemon.
- #ploop ⇒ Object
- #psleep(sec) ⇒ Object
- #pwake ⇒ Object
- #register(*signals) ⇒ Object
Constructor Details
#initialize ⇒ SelfPipeDaemon
Returns a new instance of SelfPipeDaemon.
26 27 28 29 |
# File 'lib/unicorn_horn/self_pipe_daemon.rb', line 26 def initialize SELF_PIPE.replace(IO.pipe) SELF_PIPE.each { |io| io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) } end |
Instance Method Details
#forget ⇒ Object
45 46 47 48 49 |
# File 'lib/unicorn_horn/self_pipe_daemon.rb', line 45 def forget @signals.each { |sig| trap(sig, nil) } SIG_QUEUE.clear SELF_PIPE.each { |io| io.close rescue nil } end |
#ploop ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/unicorn_horn/self_pipe_daemon.rb', line 31 def ploop Utils.proc_name 'master' logger.info "master process ready" begin yield SIG_QUEUE.shift rescue => e logger.error "Unhandled master loop exception #{e.inspect}." logger.error e.backtrace.join("\n") end while true logger.info "master complete" end |
#psleep(sec) ⇒ Object
10 11 12 13 14 |
# File 'lib/unicorn_horn/self_pipe_daemon.rb', line 10 def psleep(sec) IO.select([ SELF_PIPE[0] ], nil, nil, sec) or return SELF_PIPE[0].read_nonblock(16*1024, "") rescue Errno::EAGAIN, Errno::EINTR end |
#pwake ⇒ Object
16 17 18 19 |
# File 'lib/unicorn_horn/self_pipe_daemon.rb', line 16 def pwake SELF_PIPE[1].write_nonblock('.') # wakeup master process from select rescue Errno::EAGAIN, Errno::EINTR end |
#register(*signals) ⇒ Object
21 22 23 24 |
# File 'lib/unicorn_horn/self_pipe_daemon.rb', line 21 def register *signals @signals = signals signals.each { |sig| trap(sig){ |sig_nr| SIG_QUEUE << sig; pwake } } end |