Class: Foodtaster::ServerProcess
- Inherits:
-
Object
- Object
- Foodtaster::ServerProcess
- Defined in:
- lib/foodtaster/server_process.rb
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(drb_port) ⇒ ServerProcess
constructor
A new instance of ServerProcess.
- #output ⇒ Object
- #terminate ⇒ Object
Constructor Details
#initialize(drb_port) ⇒ ServerProcess
Returns a new instance of ServerProcess.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/foodtaster/server_process.rb', line 5 def initialize(drb_port) Foodtaster.logger.debug "Starting Foodtaster specs run" vagrant_binary = Foodtaster.config.vagrant_binary _, @pipe_out, thread = Open3.popen2("#{vagrant_binary} foodtaster-server #{drb_port}", pgroup: true, err: [:child, :out]) @pid = thread.pid @pgid = Process.getpgid(@pid) Foodtaster.logger.debug "Started foodtaster-server on port #{drb_port} with PID #{@pid}" end |
Instance Method Details
#alive? ⇒ Boolean
23 24 25 |
# File 'lib/foodtaster/server_process.rb', line 23 def alive? Process.kill(0, @pid) == 1 rescue false end |
#output ⇒ Object
19 20 21 |
# File 'lib/foodtaster/server_process.rb', line 19 def output @pipe_out.read end |
#terminate ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/foodtaster/server_process.rb', line 27 def terminate if alive? @pipe_out.close if @pgid > 0 Process.kill("TERM", -@pgid) Process.waitpid(-@pgid) rescue nil Foodtaster.logger.debug "Terminated Foodtaster DRb Server process" end end end |