Class: Guard::RackRunner
- Inherits:
-
Object
- Object
- Guard::RackRunner
- Defined in:
- lib/guard/rack/runner.rb
Constant Summary collapse
- MAX_WAIT_COUNT =
10
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #build_rack_command ⇒ Object
-
#initialize(options) ⇒ RackRunner
constructor
A new instance of RackRunner.
- #kill(pid) ⇒ Object
- #pid ⇒ Object
- #pid_file ⇒ Object
- #remove_pid_file ⇒ Object
- #restart ⇒ Object
- #sleep_time ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ RackRunner
Returns a new instance of RackRunner.
10 11 12 |
# File 'lib/guard/rack/runner.rb', line 10 def initialize() @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/guard/rack/runner.rb', line 8 def @options end |
Instance Method Details
#build_rack_command ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/guard/rack/runner.rb', line 44 def build_rack_command = [ '--env', [:environment], '--port', [:port], '--pid', pid_file ] << '--daemonize' if [:daemon] << '--debug' if [:debugger] %{sh -c 'cd #{Dir.pwd} && rackup #{.join(' ')} &'} end |
#kill(pid) ⇒ Object
14 15 16 17 |
# File 'lib/guard/rack/runner.rb', line 14 def kill pid system %{kill -INT #{pid}} $?.exitstatus end |
#pid ⇒ Object
61 62 63 |
# File 'lib/guard/rack/runner.rb', line 61 def pid File.file?(pid_file) ? File.read(pid_file).to_i : nil end |
#pid_file ⇒ Object
57 58 59 |
# File 'lib/guard/rack/runner.rb', line 57 def pid_file File.(".guard-rack-#{[:environment]}.pid") end |
#remove_pid_file ⇒ Object
65 66 67 |
# File 'lib/guard/rack/runner.rb', line 65 def remove_pid_file FileUtils.rm pid_file if File.exist? pid_file end |
#restart ⇒ Object
40 41 42 |
# File 'lib/guard/rack/runner.rb', line 40 def restart stop and start end |
#sleep_time ⇒ Object
69 70 71 |
# File 'lib/guard/rack/runner.rb', line 69 def sleep_time [:timeout].to_f / MAX_WAIT_COUNT.to_f end |
#start ⇒ Object
19 20 21 22 23 |
# File 'lib/guard/rack/runner.rb', line 19 def start kill_unmanaged_pid! if [:force_run] run_rack_command! wait_for_pid end |
#stop ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/guard/rack/runner.rb', line 25 def stop # Rely on kill_unmanaged_pid if there's no pid file return true unless File.file?(pid_file) if kill(pid) == 0 wait_for_no_pid remove_pid_file else UI.info "Rackup exited with non-zero exit status whilst trying to stop." return false end true end |