【问题标题】:run node.js by pm2,but often restart:exited with code [0] via signal [SIGINT]通过 pm2 运行 node.js,但经常重启:通过信号 [SIGINT] 使用代码 [0] 退出
【发布时间】:2023-04-10 15:27:01
【问题描述】:

我正在尝试在我的系统上运行 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

【问题讨论】:

  • 没有pm2你的代码能正常运行吗?

标签: javascript node.js pm2


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    在使用 3rd-party 实用程序运行 pm2 时,我收到了类似的错误消息:

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

    PM2 只是不断重启实用程序。

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

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

    解决方案/解决方法

    我们发现,如果我们使用 pm2在集群模式下运行该实用程序而不是 fork 模式(参见下面的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 版本。

    【讨论】:

    • 添加集群对我有用,我想有时我们可能需要在启动 pm2 之前运行 pm2 delete all 一次
    【解决方案3】:

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

    【讨论】:

    • 你可以用这个命令检查ubuntu中的cpu核心:grep -c ^processor /proc/cpuinfo
    【解决方案4】:

    请检查您的

    app.listen(portid,"private_ip");

    在我的例子中,这是被注释的行,当我取消注释它的工作时

    【讨论】:

    • 这一行在哪个文件中?我在哪里可以找到它?
    猜你喜欢
    • 2020-12-28
    • 2020-03-15
    • 1970-01-01
    • 2013-03-14
    • 2021-10-17
    • 2022-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多