class Guard::GoliathRunner
Attributes
options[R]
pid[R]
Public Class Methods
new(options)
click to toggle source
# File lib/guard/goliath/runner.rb, line 9 def initialize(options) @options = options end
Public Instance Methods
restart()
click to toggle source
# File lib/guard/goliath/runner.rb, line 33 def restart stop && start end
start()
click to toggle source
# File lib/guard/goliath/runner.rb, line 13 def start kill_unmanaged_pid! if options[:force_run] @pid = run_rack_command! true end
stop()
click to toggle source
# File lib/guard/goliath/runner.rb, line 19 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 "Ruby exited with non-zero exit status (#{exitstatus}) whilst trying to stop." return false end true end
Private Instance Methods
build_rack_command()
click to toggle source
# File lib/guard/goliath/runner.rb, line 39 def build_rack_command command = %w{ruby} command.push( options[:app_file], '--environment', options[:environment].to_s, '--port', options[:port].to_s ) command << '--daemonize' if options[:daemon] command << '-sv' unless options[:supress_output] command.push('--config', options[:config]) if options[:config] command end
kill(pid, force = false)
click to toggle source
# File lib/guard/goliath/runner.rb, line 53 def kill(pid, force = false) result = -1 UI.debug("Trying to kill app (PID #{pid})...") unless force Process.kill('INT', pid) begin Timeout.timeout(options[:timeout]) do _, status = Process.wait2(pid) result = status.exitstatus UI.debug("Killed App (Exit status: #{result})") end rescue Timeout::Error UI.debug("Couldn't kill App with INT, switching to TERM") force = true end end Process.kill('TERM', pid) if force result end
kill_unmanaged_pid!()
click to toggle source
# File lib/guard/goliath/runner.rb, line 86 def kill_unmanaged_pid! pid = unmanaged_pid kill(pid, true) if pid end
run_rack_command!()
click to toggle source
# File lib/guard/goliath/runner.rb, line 76 def run_rack_command! command = build_rack_command UI.debug("Running App with command: #{command.inspect}") spawn(*command) end
spawn(* args)
click to toggle source
# File lib/guard/goliath/runner.rb, line 82 def spawn(* args) Spoon.spawnp(* args) end
unmanaged_pid()
click to toggle source
# File lib/guard/goliath/runner.rb, line 91 def unmanaged_pid %x{lsof -n -i TCP:#{options[:port]}}.each_line do |line| return line.split("\s")[1].to_i if line["*:#{options[:port]} "] end nil end