-
-
Save slayer/179610 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'daemons' | |
module Daemons | |
class Monitor | |
def stop | |
pid = @pid.pid | |
begin; Process.kill('TERM', pid); rescue ::Exception; end | |
sleep(0.5) | |
begin; Process.kill('KILL', pid); rescue ::Exception; end | |
# We try to remove the pid-files by ourselves, in case the application | |
# didn't clean it up. | |
begin; @pid.cleanup; rescue ::Exception; end | |
end | |
end | |
class Application | |
def stop | |
if options[:force] and not running? | |
self.zap | |
return | |
end | |
# Catch errors when trying to kill a process that doesn't | |
# exist. This happens when the process quits and hasn't been | |
# restarted by the monitor yet. By catching the error, we allow the | |
# pid file clean-up to occur. | |
pid = @pid.pid | |
begin | |
Process.kill('TERM', pid) | |
sleep(0.5) | |
Process.kill('KILL', pid) if running? | |
rescue Errno::ESRCH => e | |
puts "#{e} #{pid}" | |
puts "deleting pid-file." | |
end | |
# We try to remove the pid-files by ourselves, in case the application | |
# didn't clean it up. | |
begin; @pid.cleanup; rescue ::Exception; end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment