Module: Asir::Transport::Conduit
- Defined in:
- lib/asir/transport/conduit.rb
Overview
Conduit service support.
Instance Attribute Summary collapse
-
#conduit_host ⇒ Object
Returns the value of attribute conduit_host.
-
#conduit_options ⇒ Object
Returns the value of attribute conduit_options.
-
#conduit_pid ⇒ Object
Returns the value of attribute conduit_pid.
Instance Method Summary collapse
- #_close_stdio! ⇒ Object
- #_start_conduit! ⇒ Object
- #conduit_status ⇒ Object
- #start_conduit!(options = nil) ⇒ Object
- #stop_conduit!(opts = nil) ⇒ Object
Instance Attribute Details
#conduit_host ⇒ Object
Returns the value of attribute conduit_host.
7 8 9 |
# File 'lib/asir/transport/conduit.rb', line 7 def conduit_host @conduit_host end |
#conduit_options ⇒ Object
Returns the value of attribute conduit_options.
7 8 9 |
# File 'lib/asir/transport/conduit.rb', line 7 def @conduit_options end |
#conduit_pid ⇒ Object
Returns the value of attribute conduit_pid.
7 8 9 |
# File 'lib/asir/transport/conduit.rb', line 7 def conduit_pid @conduit_pid end |
Instance Method Details
#_close_stdio! ⇒ Object
34 35 36 37 38 39 |
# File 'lib/asir/transport/conduit.rb', line 34 def _close_stdio! n = ::File.open("/dev/null", "w+") [ STDIN, STDOUT, STDERR, $stdin, $stdout, $stderr ].each do | io | io.reopen(n) rescue nil end end |
#_start_conduit! ⇒ Object
66 67 68 |
# File 'lib/asir/transport/conduit.rb', line 66 def _start_conduit! raise Error::SubclassResponsibility end |
#conduit_status ⇒ Object
70 71 72 |
# File 'lib/asir/transport/conduit.rb', line 70 def conduit_status nil end |
#start_conduit!(options = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/asir/transport/conduit.rb', line 9 def start_conduit! = nil opts = @conduit_options ||= {} opts.update(:fork => true) opts.update() if _log { "start_conduit! #{self}" } if @verbose >= 1 in_fork = opts[:fork] raise "already running #{@conduit_pid} #{@conduit_cmd}" if @conduit_pid if in_fork @conduit_pid = ::Process.fork do _log { "start_conduit! #{self} starting pid=#{$$.inspect}" } if @verbose >= 2 _close_stdio! _start_conduit! raise "Could not exec" end _log { "start_conduit! #{self} started pid=#{@conduit_pid.inspect}" } if @verbose >= 2 if pid_file = (@conduit_options || EMPTY_HASH)[:pid_file] ::File.open(pid_file, "w") { | fh | fh.puts @conduit_pid } end else _close_stdio! _start_conduit! end self end |
#stop_conduit!(opts = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/asir/transport/conduit.rb', line 52 def stop_conduit! opts = nil if conduit_pid _log { "stop_conduit! #{self} pid=#{@conduit_pid.inspect}" } if @verbose >= 1 ::Process.kill( (opts && opts[:signal]) || 'TERM', @conduit_pid) if pid_file = (@conduit_options || EMPTY_HASH)[:pid_file] ::File.unlink(pid_file) rescue nil end ::Process.waitpid @conduit_pid end self ensure @conduit_pid = nil end |