supervisord如何重启npm start命令成功?

How can supervisord restart the npm start command successfully?

我已经通过 supervisord 启动了 "node start"。

我的问题是 在 supervisord 停止/重启将导致节点 app.js 进程保持不变而不会被杀死

这种情况下supervisord如何重启npm start命令成功?

supervisord.conf

[supervisord]
nodaemon=true

[program:node]
command=npm start 
directory=/xx
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
user=root
autostart=true
autorestart=true
redirect_stderr=true
exitcodes=1

package.json

{
  "name": "xx",
  "version": "1.0.0",
  "main": "app.js",
  "scripts": {
    "start": "node app.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "xxx
  },
  "devDependencies": {
    "nodemon": "^1.11.0"
  },
  "description": ""
}

这对我有用:在 Supervisor 配置文件中将 npm start 更改为 node app.js

为什么?

我注意到使用 npm start 会启动两个进程:

$ ps aux | grep node
ubuntu   19363  0.0  0.0   4508   708 ?        S    17:43   0:00 sh -c node index.js
ubuntu   19364  1.3  5.2 1041288 52996 ?       Sl   17:43   0:00 node index.js

并且在 Supervisor 中停止它只会停止父进程:

$ sudo supervisorctl stop all
my_worker: stopped
$ ps aux | grep node
ubuntu   19364  0.3  5.2 1041288 52996 ?       Sl   17:43   0:00 node index.js

所以将 node index.js 直接放在主管配置中解决了我的问题。