def stop
@pid_file = PidFile.new( DaemonKit.configuration.pid_file )
unless @pid_file.running?
@pid_file.cleanup
puts "Nothing to stop"
exit
end
target_pid = @pid_file.pid
puts "Sending TERM to #{target_pid}"
Process.kill( 'TERM', target_pid )
if seconds = DaemonKit.configuration.force_kill_wait
begin
Timeout::timeout( seconds ) do
loop do
puts "Waiting #{seconds} seconds for #{target_pid} before sending KILL"
break unless @pid_file.running?
seconds -= 1
sleep 1
end
end
rescue Timeout::Error
Process.kill( 'KILL', target_pid )
end
end
if @pid_file.running?
puts "Process still running, leaving pidfile behind! Consider using configuration.force_kill_wait."
else
@pid_file.cleanup
end
end