When I stop the upstart, SIGTERM is used by default. I grabbed SIGTERM in node.js as:
process.on('SIGTERM', shutdownServerGracefully);
process.on('SIGINT', shutdownServerGracefully);
I checked that this works by running it from the terminal and sending kill -s SIGTERM [pid]. This causes a graceful shutdown, and I see it in the logs.
I have an upstart script that looks like this:
start on runlevel [2345]
stop on runlevel [016]
respawn
respawn limit 5 30
kill timeout 300
kill signal SIGTERM
normal exit 0 SIGTERM SIGINT SIGQUIT
chdir /var/web_server
script
. /etc/environment
export NODE_ENV
mkfifo /tmp/log-fifo
( logger -t web < /tmp/log-fifo & )
exec > /tmp/log-fifo
rm /tmp/log-fifo
node server.js
end script
When I start work, everything works fine. When I stop working, the node process is immediately killed, node never processes the SIGTERM signal.
If I change upstart conf to kill signal SIGINT, the node process will get SIGINT and the shutdown will be elegant. WTF?
SIGINT , SIGTERM? node SIGTERM , Upstart, SIGINT? Upstart?