Sha256: 4bc3f873a336b722171b59580452afd2bc10e73b0fd1f41b333d2f3c4f4a01b4

Contents?: true

Size: 938 Bytes

Versions: 7

Compression:

Stored size: 938 Bytes

Contents

require 'open3'

module Foodtaster
  class ServerProcess
    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

    def output
      @pipe_out.read
    end

    def alive?
      Process.kill(0, @pid) == 1 rescue false
    end

    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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foodtaster-0.0.10 lib/foodtaster/server_process.rb
foodtaster-0.0.9 lib/foodtaster/server_process.rb
foodtaster-0.0.8 lib/foodtaster/server_process.rb
foodtaster-0.0.7 lib/foodtaster/server_process.rb
foodtaster-0.0.6 lib/foodtaster/server_process.rb
foodtaster-0.0.4 lib/foodtaster/server_process.rb
foodtaster-0.0.3 lib/foodtaster/server_process.rb