I have an application with cluster and Forever. I want to save information from workers before shutdown or restart of the app. So I use process.on('SIGINT') and that works fine for CTRL+C.
But I have stuck with Forever. Is it possible to detect somehow the app was restarted by Forever? Is there any signal about that?
This issue is quite old, but for those who did not saw it, the lastest forever versions support --killSignal (this has been added in dec 2013) so you can use by example --killSignal=SIGUSR2 and catch this signal with process.on('SIGUSR2', func)
Forever uses a SIGKILL see https://github.com/nodejitsu/forever-monitor/blob/master/lib/forever-monitor/monitor.js#L353
So add process.on('SIGKILL', onStop); to your process.on('SIGINT', onStop); though note that after that forever uses kill https://github.com/nodejitsu/forever-monitor/blob/master/lib/forever-monitor/common.js#L45 which sends a 'SIGTERM', so process.on('SIGTERM', onStop) as well.
I'd suggest to do kill -s SIGUSR1 <pid> before restarting your daemon. This signal can be easily caught in node by process.on('SIGUSR1').
kill -s SIGUSR1 <pid>
forever restart test.js
forever has a option --killSignal, you can customize it to other caughtable signals(such as SIGINT), then in your app, use process.on('SIGINT', ...) to caught it. There is a official example , the console.log statements have no effect in signal handler, I think it's a bug, hopes fix soon.