class Foodtaster::ServerProcess

Public Class Methods

new(drb_port) click to toggle source
# 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

Public Instance Methods

alive?() click to toggle source
# File lib/foodtaster/server_process.rb, line 23
def alive?
  Process.kill(0, @pid) == 1 rescue false
end
output() click to toggle source
# File lib/foodtaster/server_process.rb, line 19
def output
  @pipe_out.read
end
terminate() click to toggle source
# 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