Hopefully this question has an answer that's generic to Apache and Node.js, and not specific to Plesk ('cause I know how you feel about Plesk-specific questions!).
I recently decided to add some text message notifications to a Node.js server app, for when a particular update was discovered. While I was at it, I figured it would be a good idea to add a server start-up and shutdown notifications too. This led to a few of unpleasant discoveries:
- Roughly every 24 hours my server (not the entire server platform, just this one Node.js server app) was restarting for no good reason, between 3:30-4:30 AM.
- There was no graceful detection of a shutdown before each restart, so it appears that the Node.js app was being killed outright, not sent SIGINT or SIGTERM, which I was listening for.
- Even using the (cough) control panel, where you can request an app restart, a graceful restart doesn't occur. The Node.js app is simply unceremoniously killed.
The once-per-24-hour restart, after some investigation, is apparently triggered by Apache log rotation. Why simple log rotation should cause this is another mystery to be solved.
In the meantime, I want to know if there's a way to make sure GRACEFUL shutdowns happen, whether they happen because Apache is stopping or shutting down, or because the "Restart App" button is pressed.
I look for shutdowns by monitoring these signals:
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);
process.on('SIGUSR2', shutdown); // Used by my dev tools
Is there a different signal I should check for?
Is the process shutdown mercilessly with a SIGKILL instead?
If so, can I change that, perhaps with some sort of delay to give a graceful shutdown some time to occur?