From: Tim Pease Date: 2007-09-29T23:43:14+09:00 Subject: Re: trapping TERM in a daemonized (Daemon gem) script On 9/28/07, Dean Holdren wrote: > I'm using the Daemon gem, and I'd like to trap the TERM signal so that > I can have graceful termination of my main execution loop: > > $running = true; > Signal.trap("TERM") do > $running = false > end > > while($running) do > #some operations that could take a few seconds > sleep(5) > end > > However, I get some memory errors when I stop the process, and I can > sometimes get an extra process after a 'restart' is issued, that I > can't kill with a 'stop' > > I looked at the source to the Daemon gem, and it warns not to trap the > TERM signal in your script. So how can I gracefully end my loop if I > don't trap TERM? > You can trap any signal and use that to terminate your script. Try the interrupt signal. Signal.trap('INT') do end To send this to your daemon process on a *NIX host ... kill -SIGINT pid Blessings, TwP