Thursday, March 31, 2011

Detect stop with Ruby Daemons gem.

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?

From stackoverflow
  • 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
    
    gregf : at_exit worked just fine, thanks a lot.
  • Rapleaf had a pretty good article on their blog about an extension to the Daemons gem that might be what you're looking for.

0 comments:

Post a Comment