为什么node.js不能从upstart脚本中捕获SIGTERM?

时间:2016-08-27 17:46:56

标签: linux ubuntu upstart

当我停止新手工作时,默认情况下它使用SIGTERM。我在node.js中捕获了SIGTERM,如:

process.on('SIGTERM', shutdownServerGracefully);
process.on('SIGINT', shutdownServerGracefully);

我通过从终端运行并发送kill -s SIGTERM [pid]来验证这是有效的。这会触发正常关机,我会在日志中看到它。

我有一个看起来像这样的upstart脚本:

# Process will start after a network is available.
start on runlevel [2345]
stop on runlevel [016]

# Keep server running
respawn
respawn limit 5 30

# Wait 5 minutes for server to gracefully shutdown
kill timeout 300
# Allow for graceful shutdown
kill signal SIGTERM
normal exit 0 SIGTERM SIGINT SIGQUIT
chdir /var/web_server

script
  # Environment variables
  . /etc/environment
  export NODE_ENV

  # Setup all stdout and stderr to go to a named pipe
  mkfifo /tmp/log-fifo
  ( logger -t web < /tmp/log-fifo & )
  exec > /tmp/log-fifo
  rm /tmp/log-fifo

  node server.js --env="$NODE_ENV" 2>&1
end script

当我开始工作时,一切正常。当我停止作业时,节点进程立即被终止,节点永远不会处理SIGTERM信号。

如果我将upstart conf更改为kill signal SIGINT,则节点进程将获得SIGINT并正常关闭。 WTF?

为什么SIGINT正常工作但不是SIGTERM?为什么我的节点进程完全能够在从终端运行时捕获SIGTERM,但在通过Upstart运行时却不能,但是它能够捕获SIGINT?这是Upstart中的怪癖还是错误?

0 个答案:

没有答案
相关问题