class Kik::Runner
Public Class Methods
new(port, verbose, command)
click to toggle source
# File lib/kik/runner.rb, line 3 def initialize(port, verbose, command) @port, @command, @verbose = port, command, verbose end
Public Instance Methods
start()
click to toggle source
# File lib/kik/runner.rb, line 7 def start puts "Running `#{@command.join(' ')}' watching port #{@port} for a listener!" if @verbose while true run_command unless check_port sleep 5 end end
Private Instance Methods
check_port()
click to toggle source
# File lib/kik/runner.rb, line 16 def check_port out = `lsof -i :#{@port}` out.strip! listening = !out.empty? puts "Checked port #{@port}, it is #{listening ? 'listening' : 'not listening'}" if @verbose listening end
clean_child!()
click to toggle source
# File lib/kik/runner.rb, line 30 def clean_child! return unless @child_pid begin return unless Process.kill(0, @child_pid) == 1 puts "Child process still alive, killing" if @verbose Process.kill(9, @child_pid) rescue Errno::ESRCH # do nothing end end
run_command()
click to toggle source
# File lib/kik/runner.rb, line 25 def run_command clean_child! @child_pid = Process.spawn(*@command) end