Node.JS Shutdown Hook

Is it possible to intercept the default signal killand use it as a command to gracefully disconnect? This is for Solaris SMF. The easiest way to find a stopped service that I found is to set the :killscript as a shutdown, and then add a trailing hook to it. In this case, I want to do this for Node.JS. How should I do it?

Edit: The goal is to

  • Stop receiving new requests.
  • Provide existing callbacks for a few seconds.
  • Enter some information in stderr.

@alienhard the first sentence was to use process.on('exit'..., but it seems like I could not execute number 2 with this method.

+3
source share
2

exit: http://nodejs.org/docs/v0.3.1/api/process.html#event_exit_

process.on('exit', function() {
  console.log('About to exit.');
});

: , , , , , SIGUSR1 (kill -s SIGUSR1), (. , @masylum ), , - , process.exit().

+9

All Articles