1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
require "spring/version"
module Spring
module Client
class Stop < Command
TIMEOUT = 2 # seconds
def self.description
"Stop all spring processes for this project."
end
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
def kill(sig)
pid = env.pid
Process.kill(sig, pid) if pid
rescue Errno::ESRCH
# already dead
end
end
end
end
|