0

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:

  1. 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.
  2. 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.
  3. 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.

Node.js Restart App button

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?

kshetline
  • 109
  • 1
  • 7
  • Have you checked your app's log? – Michael Hampton Aug 23 '21 at 19:47
  • There's nothing helpful there I can see, unless I don't know the right logs to look at. In the Apache logs, I see nothing. In `/var/log/httpd/error_log`, where all Node.js output goes (whether it's from stdout or stderr), all I see is my Node.js running merrily along, then restarting without a hint as to why it needed to restart. – kshetline Aug 23 '21 at 20:30
  • I think there's very little at this point that we can do. You'll need to dig into whatever Plesk is doing, either when you click that restart button or whatever it does at 3:30 am, most likely both. – Michael Hampton Aug 23 '21 at 20:47
  • I wasn't sure if this problem was Plesk specific, or if there might be a standard implementation for using Node.js with Apache, and general Apache-related advice. I posted a few days ago talk.plesk.com, and so far... crickets! – kshetline Aug 24 '21 at 00:26
  • When I entered 'plesk' as a tag for this post, there was a warning for that tag that most questions about Plesk belonged on webmasters.stackexchange.com. This same question there, however, got closed as off-topic, so I hope someone can help here. The Plesk forum is dead quiet on the matter. – kshetline Aug 24 '21 at 02:20
  • There's no standard way to start a Node.js app. You'll have to find out how Plesk does it, and that's not something we can help with. – Michael Hampton Aug 24 '21 at 12:30

0 Answers0