Ruby Daemons Stone Stop Detection

I use ruby daemon gem. I wonder how I can add extra steps to a stop action? I was hoping that I could detect that the call was called and add extra code to it. Does anyone know how I can do this?

+5
source share
3 answers

Looking at the daemon code, it doesn't seem like there is an obvious extension point for this purpose. However, I am wondering if (in a demonized process) it can capture the KILL / TERM signal that the daemons send when the “stop” occurs ...?

trap("TERM") do
  # execute your extra code here
end

Alternatively, you can set the at_exit hook: -

at_exit do
  # execute your extra code here
end
+6
source

Rapleaf Daemons, , .

+4

After reading Daemons docs, I found that there is an option :stop_procin the # start method

: stop_proc A proc that will be called when the demonized process receives a stop request (only works for: load and: proc mode)

That way you can pass it as an option with # run or # run_proc

Original link for a response to rubyforge

+2
source

All Articles