通过pm2运行node.js,但经常重启:通过信号[SIGINT]退出代码[0]

时间:2016-06-03 10:34:06

标签: javascript node.js pm2

我正在尝试在我的系统上运行node.js但遇到了这个问题:

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

我使用pm2运行node.js,但由于以下原因,它经常重启:exited with code [0] via signal [SIGINT]。这是为什么?

其他一些信息:

~$ 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

4 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,其中pm2每秒钟重新启动一次,并且正常运行时间为0s。我找到了解决方法:

  1. pm2 start bin/www -i 0 //这将启动集群和主应用程序
  2. pm2 stop 0 //这将允许群集继续运行

答案 1 :(得分:0)

使用第三方工具运行pm2时,我也遇到类似的错误消息:

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

PM2一直在重新启动该实用程序。

我尝试在没有pm2的情况下运行该实用程序,但实际上并没有退出。我想知道为什么pm2决定重新启动该实用程序。 (尚无答案,尽管从日志来看,这是由于SIGINT)

我们不希望该实用程序继续重启。

解决方案/解决方法

发现的结果是,如果我们使用pm2来以群集模式(而不是派生模式)运行该实用程序(请参阅下面的exec_mode: 'cluster_mode'),则该实用程序可以正常工作而无需重新启动。

pm2.utility.config.js

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

module.exports = pm2Config

然后运行pm2:

pm2 start pm2.utility.config.js

注意:我的pm2版本为3.4.0。

答案 2 :(得分:0)

请检查您

  

app.listen(portid,“ private_ip”);

在我的情况下,这行会被评论,而当我取消评论它的工作时

答案 3 :(得分:0)

如果您正在群集模式下运行pm2,并尝试创建多个实例(超过1个)并收到报告的错误,请检查您的计算机有多少个CPU核心。因为如果您的cpu只有一个内核,并且您尝试使用更多的pm2运行,那么一个实例会出错,但是分叉​​模式不会给您错误。