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

neg*_*aro 4 node.js supervisord

我已经通过supervisord启动了“节点启动”。

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

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

主管配置文件

[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
Run Code Online (Sandbox Code Playgroud)

包.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": ""
}
Run Code Online (Sandbox Code Playgroud)

dus*_*san 5

这对我有用:更改npm startnode app.jsSupervisor 配置文件内部。

为什么?

我注意到 usingnpm 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
Run Code Online (Sandbox Code Playgroud)

在 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
Run Code Online (Sandbox Code Playgroud)

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