class Guard::RackRunner

Attributes

options[R]
pid[R]

Public Class Methods

new(options) click to toggle source
# File lib/guard/rack/runner.rb, line 10
def initialize(options)
  @options = options
end

Public Instance Methods

restart() click to toggle source
# File lib/guard/rack/runner.rb, line 34
def restart
  stop && start
end
start() click to toggle source
# File lib/guard/rack/runner.rb, line 14
def start
  kill_unmanaged_pid! if options[:force_run]
  @pid = run_rack_command!
  true
end
stop() click to toggle source
# File lib/guard/rack/runner.rb, line 20
def stop
  # Rely on kill_unmanaged_pid if there's no pid
  return true unless @pid

  exitstatus = kill(@pid)
  @pid = nil
  if exitstatus && exitstatus != 0
    UI.info "Rackup exited with non-zero exit status (#{exitstatus}) whilst trying to stop."
    return false
  end

  true
end

Private Instance Methods

kill(pid, force = false) click to toggle source
# File lib/guard/rack/runner.rb, line 40
def kill(pid, force = false)
  Guard::Rack::CustomProcess.new(options).kill pid, force
end
kill_unmanaged_pid!() click to toggle source
# File lib/guard/rack/runner.rb, line 54
def kill_unmanaged_pid!
  pid = unmanaged_pid
  kill(pid, true) if pid
end
run_rack_command!() click to toggle source
# File lib/guard/rack/runner.rb, line 44
def run_rack_command!
  command = Guard::Rack::Command.new(options).build
  UI.debug("Running Rack with command: #{command}")
  spawn(*command)
end
spawn(* args) click to toggle source
# File lib/guard/rack/runner.rb, line 50
def spawn(* args)
  Spoon.spawnp(* args)
end
unmanaged_pid() click to toggle source
# File lib/guard/rack/runner.rb, line 59
def unmanaged_pid
  `lsof -n -i TCP:#{options[:port]}`.each_line do |line|
    return line.split("\s")[1].to_i if line["*:#{options[:port]} "]
  end
  nil
end