I'm using the ruby daemon gem. Wondering how I can add some extra steps to the stop action? Was hoping I could detect stop was called, and add some extra code to it. Anyone know how I can accomplish this?
Looking at the daemon gem code, it doesn't look like it has an obvious extension point for this purpose. However, I wonder if (in the daemonized process) you could trap the KILL/TERM signal that daemons sends when a 'stop' occurs...?
trap("TERM") do
# execute your extra code here
end
Alternatively you could install an at_exit hook :-
at_exit do
# execute your extra code here
end
Rapleaf had a pretty good article on their blog about an extension to the Daemons gem that might be what you're looking for.
After reading Daemons docs I found that there is a :stop_proc
option in the #run method
:stop_proc A proc that will be called when the daemonized process receives a request to stop (works only for :load and :proc mode)
So basically you can pass it as an option with the #run or #run_proc methods
Original answer's link to rubyforge
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With