run node.js by pm2,but often restart:exited with code [0] via signal [SIGINT]

人盡茶涼 提交于 2020-05-27 08:04:26

问题


I am trying to run node.js on my system but running into this problem:

2016-06-01 20:46:28: App [app] with id [13] and pid [12633], exited with code [0] via signal [SIGINT]
2016-06-01 20:46:28: Starting execution sequence in -cluster mode- for app name:app id:13
2016-06-01 20:46:28: App name:app id:13 online
2016-06-01 20:46:28: App name:app id:4 disconnected
2016-06-01 20:46:28: App [app] with id [4] and pid [47284], exited with code [0] via signal [SIGINT]
2016-06-01 20:46:28: Starting execution sequence in -cluster mode- for app name:app id:4
2016-06-01 20:46:29: App name:app id:4 online
2016-06-01 20:46:44: App name:app id:3 disconnected
2016-06-01 20:46:44: App [app] with id [3] and pid [42456], exited with code [0] via signal [SIGINT]
2016-06-01 20:46:44: Starting execution sequence in -cluster mode- for app name:app id:3
2016-06-01 20:46:44: App name:app id:3 online
2016-06-01 20:46:45: App name:app id:2 disconnected
2016-06-01 20:46:45: App [app] with id [2] and pid [47045], exited with code [0] via signal [SIGINT]
2016-06-01 20:46:45: Starting execution sequence in -cluster mode- for app name:app id:2
2016-06-01 20:46:45: App name:app id:2 online
2016-06-01 20:46:49: App name:app id:6 disconnected
2016-06-01 20:46:49: App [app] with id [6] and pid [47326], exited with code [0] via signal [SIGINT]
2016-06-01 20:46:49: Starting execution sequence in -cluster mode- for app name:app id:6
2016-06-01 20:46:49: App name:app id:6 online
2016-06-01 20:46:49: App name:app id:10 disconnected
2016-06-01 20:46:49: App [app] with id [10] and pid [47291], exited with code [0] via signal [SIGINT]
2016-06-01 20:46:49: Starting execution sequence in -cluster mode- for app name:app id:10
2016-06-01 20:46:49: App name:app id:10 online
2016-06-01 20:48:33: App name:app id:2 disconnected

I run node.js using pm2, but it often restarts because of the following: exited with code [0] via signal [SIGINT]. Why is this?

Some additional information:

~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       40G  9.8G   28G  27% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            7.9G  4.0K  7.9G   1% /dev
tmpfs           1.6G  380K  1.6G   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            7.9G     0  7.9G   0% /run/shm
none            100M     0  100M   0% /run/user

~$ free -m
 total       used       free     shared    buffers     cached
Mem:         16035       8177       7857          0        174       3672
-/+ buffers/cache:       4331      11704
Swap:            0          0          0

~$ node -v
v5.1.1

~$ npm -v
3.3.12

回答1:


I had similar error message when running pm2 with a 3rd-party utility:

PM2 | App [Utility:2] exited with code [1] via signal [SIGINT]

PM2 just kept restarting the utility.

And I tried running the utility without pm2, it did not actually exit. I was wondering why pm2 decided to restart the utility. (No answer yet, though from the log, it's due to SIGINT)

We don't want the utility to keep restarting.

Solution / Workaround

What we found is, if we use pm2 to run the utility in cluster mode instead of fork mode(see exec_mode: 'cluster_mode' below), the utility works without keeping restarting.

pm2.utility.config.js

const pm2Config = {
  apps: [
    {
      name: 'Utility',
      script: './3rd/utility.js',
      exec_mode: 'cluster_mode',
      instances: 1,
    },
  ],
}

module.exports = pm2Config

Then run pm2:

pm2 start pm2.utility.config.js

Note: my pm2 is of version 3.4.0.




回答2:


I was having the same issue where pm2 was restarting every second and uptime was 0s. I found a work around:

  1. pm2 start bin/www -i 0 // this will start a cluster and the main app
  2. pm2 stop 0 // this will allow the cluster to keep running



回答3:


please check you

app.listen(portid,"private_ip");

line in my case this is commented and when i uncommented its work




回答4:


If your are running pm2 in cluster mode and trying to create instances more than 1 and getting the error you reported, check how many cpu core your machine has. Because if your cpu has got only one core and you are trying to run pm2 with more then one instance you will get error however forking mode will not give you error.



来源:https://stackoverflow.com/questions/37612081/run-node-js-by-pm2-but-often-restartexited-with-code-0-via-signal-sigint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!