以下是 pm2 process.json配置文件。该应用程序使用命令凝视
pm2 开始 /root/src/sample_v2/deploy-scripts/processes.json
{
"apps" : [{
"name" : "sample_app_v2",
"script" : "bin/www",
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"node_args" : "--harmony",
"cwd" : "/root/src/sample_v2",
"env": {
"NODE_ENV": "production",
"AWESOME_SERVICE_API_TOKEN": "xxx",
"TZ": "Europe/Amsterdam"
}
}]
}
输出
PM2: 2015-03-31 17:58:58: Starting execution sequence in -fork mode- for app name:sample id:10
PM2: 2015-03-31 17:58:58: App name:sample id:10 online
sample-10 (out): 2015-02-06 21:38 +04:00: Started...[object Object]
sample-10 (out): 2015-02-06 21:38 +04:00: mongoclient.connect
sample-10 (out): 2015-02-06 21:38 +04:00: Started...[object Object]
sample-10 (out): 2015-02-06 21:38 +04:00: mongoclient.connect
sample-10 (out): 2015-02-06 21:39 +04:00: Started...[object Object]
sample-10 (out): 2015-02-06 21:39 +04:00: mongoclient.connect
sample-10 (out): 2015-02-06 21:39 +04:00: Started...[object Object]
sample-10 (out): 2015-02-06 21:39 +04:00: mongoclient.connect
sample-10 (out): 2015-02-06 21:39 +04:00: Started...[object Object]
sample-10 (out): 2015-02-06 21:39 +04:00: mongoclient.connect
sample-10 (out): 2015-02-06 21:39 +04:00: Started...[object Object]
sample-10 (out): 2015-02-06 21:39 +04:00: mongoclient.connect
sample-10 (out): 2015-02-06 21:39 +04:00: Started...[object Object]
sample-10 (out): 2015-02-06 21:39 +04:00: mongoclient.connect
sample-10 (out): 2015-03-31 17:59 +04:00: Started...[object Object]
sample-10 (err): at Object.274:1 (cluster.js:594:5)
sample-10 (err): at handleResponse (cluster.js:171:41)
sample-10 (err): at respond (cluster.js:192:5)
sample-10 (err): at handleMessage (cluster.js:202:5)
sample-10 (err): at process.emit (events.js:117:20)
sample-10 (err): at handleMessage (child_process.js:322:10)
sample-10 (err): at child_process.js:396:7
sample-10 (err): at process.handleConversion.net.Native.got (child_process.js:91:7)
sample-10 (err): at process.<anonymous> (child_process.js:395:13)
sample-10 (err): TypeError: Cannot read property 'getsockname' of undefined
sample-10 (err): at net.js:1083:27
sample-10 (err): at Object.274:1 (cluster.js:594:5)
sample-10 (err): at handleResponse (cluster.js:171:41)
sample-10 (err): at respond (cluster.js:192:5)
sample-10 (err): at handleMessage (cluster.js:202:5)
sample-10 (err): at process.emit (events.js:117:20)
sample-10 (err): at handleMessage (child_process.js:322:10)
sample-10 (err): at child_process.js:396:7
sample-10 (err): at process.handleConversion.net.Native.got (child_process.js:91:7)
sample-10 (err): at process.<anonymous> (child_process.js:395:13)
看起来该过程已尝试启动10次。如何要求pm2不启动多个实例?
编辑2:
添加属性
"instances" : 1
到 json 文件按预期工作,并且只启动一个进程。但它会引发警告
[WARN] You should not use the cluster_mode (-i) in production, it's still a beta feature. A front HTTP load balancer or interaction with NGINX will be developped in the future.
如何在fork 模式下启动进程并且仍然有单个实例。