V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
tofishes
V2EX  ›  Node.js

PM2 启动管理多个 app 出现 id 混乱是神马情况?

  •  
  •   tofishes · 2016-07-08 16:42:00 +08:00 · 6128 次点击
    这是一个创建于 3090 天前的主题,其中的信息可能已经有所发展或是发生改变。

    首先我使用了不同的启动方式:

    pm2 start index.js
    pm2 start process.json
    

    启动了 3 个 app ,第一次执行是正常的:

    $ pm2 list
    ┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────────────┬──────────┐
    │ App name │ id │ mode │ pid   │ status │ restart │ uptime │ memory      │ watching │
    ├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────────────┼──────────┤
    │ index    │ 0  │ fork │ 48337 │ online │ 0       │ 2m     │ 23.746 MB   │ disabled │
    │ lianj-pc │ 1  │ fork │ 48871 │ online │ 1       │ 20s    │ 74.781 MB   │ disabled │
    │ demo     │ 2  │ fork │ 48889 │ online │ 1       │ 20s    │ 64.785 MB   │ disabled │
    └──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────────────┴──────────┘
    

    其中 index 启动端口为 8001 ,其他两个分别为 9000 , 8000 。 ** index id=0, lianj-pc id=1, demo id=2 **

    那么问题来了,当我再次单独执行 pm2 start process.json 时,启动出现了问题:

    # 节选自 pm2.log
    2016-07-08 16:10:24: Stopping app:lianj-pc id:1
    2016-07-08 16:10:24: App [lianj-pc] with id [1] and pid [48454], exited with code [0] via signal [SIGINT]
    2016-07-08 16:10:24: Starting execution sequence in -fork mode- for app name:lianj-pc id:1
    2016-07-08 16:10:24: ***App name:lianj-pc id:1 online***
    2016-07-08 16:10:24: Stopping app:demo id:2
    2016-07-08 16:10:24: App [demo] with id [2] and pid [48456], exited with code [0] via signal [SIGINT]
    2016-07-08 16:10:24: Starting execution sequence in -fork mode- for app name:demo id:2
    2016-07-08 16:10:24: ***App name:demo id:2 online***
    2016-07-08 16:11:04: Stopping app:lianj-pc id:1
    2016-07-08 16:11:04: App [lianj-pc] with id [1] and pid [48871], exited with code [0] via signal [SIGINT]
    2016-07-08 16:11:05: Starting execution sequence in -fork mode- for app name:lianj-pc id:0
    2016-07-08 16:11:05: ***App name:lianj-pc id:0 online***
    2016-07-08 16:11:05: Stopping app:demo id:2
    2016-07-08 16:11:05: App [demo] with id [2] and pid [48889], exited with code [0] via signal [SIGINT]
    2016-07-08 16:11:05: Starting execution sequence in -fork mode- for app name:demo id:0
    2016-07-08 16:11:05: ***App name:demo id:0 online***
    2016-07-08 16:11:05: App [lianj-pc] with id [0] and pid [49126], exited with code [255] via signal [SIGINT]
    2016-07-08 16:11:05: Starting execution sequence in -fork mode- for app name:demo id:0
    2016-07-08 16:11:05: App name:demo id:0 online
    2016-07-08 16:11:05: App [demo] with id [0] and pid [49144], exited with code [255] via signal [SIGINT]
    2016-07-08 16:11:05: Starting execution sequence in -fork mode- for app name:demo id:0
    2016-07-08 16:11:05: App name:demo id:0 online
    2016-07-08 16:11:05: App [demo] with id [0] and pid [49158], exited with code [255] via signal [SIGINT]
    2016-07-08 16:11:05: Starting execution sequence in -fork mode- for app name:demo id:0
    2016-07-08 16:11:05: App name:demo id:0 online
    2016-07-08 16:11:05: App [demo] with id [0] and pid [49183], exited with code [255] via signal [SIGINT]
    2016-07-08 16:11:05: Starting execution sequence in -fork mode- for app name:demo id:0
    2016-07-08 16:11:05: App name:demo id:0 online
    2016-07-08 16:11:05: App [demo] with id [0] and pid [49188], exited with code [255] via signal [SIGINT]
    "pm2.log" 11301L, 938877C
    2016-07-08 16:22:21: App [lianj-pc] with id [0] and pid [17471], exited with code [255] via signal [SIGINT]
    2016-07-08 16:22:21: Starting execution sequence in -fork mode- for app name:lianj-pc id:0
    

    请看我在日志中加了***的部分,启动 id 和 app name 的对应已经发生混乱,都对应到了 index 的 id 上去,结果就是 index 不断重启,但是又因为重复绑定端口而报错,日志如下:

    M2 App [lianj-pc] with id [0] and pid [66856], exited with code [255] via signal [SIGINT]
    PM2 Starting execution sequence in -fork mode- for app name:lianj-pc id:0
    PM2 App name:lianj-pc id:0 online
    lianj-pc-0 Error: listen EADDRINUSE 127.0.0.1:8001
    lianj-pc-0     at Object.exports._errnoException (util.js:870:11)
    lianj-pc-0     at exports._exceptionWithHostPort (util.js:893:20)
    lianj-pc-0     at Server._listen2 (net.js:1234:14)
    lianj-pc-0     at listen (net.js:1270:10)
    lianj-pc-0     at net.js:1379:9
    lianj-pc-0     at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:64:16)
    lianj-pc-0     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:83:10)
    

    想从 Google 问个究竟,却始终查不出什么,不知道大家有没有遇到的,目前来看会不会就是不能混合使用启动方式呢?

    第 1 条附言  ·  2016-07-08 17:32:58 +08:00
    补充:

    pm2 启动的 index 提供了一种网络服务,当访问 index 时,执行一个 shell 命令,该 shell 命令用于执行 另外两个 app 的重启。

    多次反复测试后,用 pm2 启动的 app 再执行 shell 命令用于重启 pm2 就发生混乱。
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5873 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 01:58 · PVG 09:58 · LAX 17:58 · JFK 20:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.