def stop(no_wait = false)
if not running?
self.zap
return
end
pid = @pid.pid
begin
Process.kill(SIGNAL, pid)
rescue Errno::ESRCH => e
puts "#{e} #{pid}"
puts "deleting pid-file."
end
if not no_wait
if @force_kill_waittime > 0
puts "#{self.group.app_name}: trying to stop process with pid #{pid}..."
STDOUT.flush
begin
Timeout::timeout(@force_kill_waittime) {
while Pid.running?(pid)
sleep(0.2)
end
}
rescue Timeout::Error
puts "#{self.group.app_name}: process with pid #{pid} won't stop, we forcefully kill it..."
STDOUT.flush
begin
Process.kill('KILL', pid)
rescue Errno::ESRCH
end
begin
Timeout::timeout(20) {
while Pid.running?(pid)
sleep(1)
end
}
rescue Timeout::Error
puts "#{self.group.app_name}: unable to forcefully kill process with pid #{pid}."
STDOUT.flush
end
end
end
end
sleep(0.1)
unless Pid.running?(pid)
begin; @pid.cleanup; rescue ::Exception; end
puts "#{self.group.app_name}: process with pid #{pid} successfully stopped."
STDOUT.flush
end
end