Class: Spring::Client::Stop

Inherits:
Command
  • Object
show all
Defined in:
lib/spring/client/stop.rb

Constant Summary collapse

TIMEOUT =

seconds

2

Instance Attribute Summary

Attributes inherited from Command

#args, #env

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

call, #initialize

Constructor Details

This class inherits a constructor from Spring::Client::Command

Class Method Details

.descriptionObject



8
9
10
# File 'lib/spring/client/stop.rb', line 8

def self.description
  "Stop all spring processes for this project."
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/spring/client/stop.rb', line 12

def call
  if env.server_running?
    timeout = Time.now + TIMEOUT
    kill 'TERM'
    sleep 0.1 until !env.server_running? || Time.now >= timeout

    if env.server_running?
      $stderr.puts "Spring did not stop; killing forcibly."
      kill 'KILL'
    else
      puts "Spring stopped."
    end
  else
    puts "Spring is not running"
  end
end

#kill(sig) ⇒ Object



29
30
31
32
33
34
# File 'lib/spring/client/stop.rb', line 29

def kill(sig)
  pid = env.pid
  Process.kill(sig, pid) if pid
rescue Errno::ESRCH
  # already dead
end