2017-09-13 164 views
0

我通常會做pm2 stop來停止我的應用程序,它工作正常。PM2刪除後無法重新啓動Node.js應用程序

但是,當我剛剛嘗試pm2刪除在我的應用程序,並再次啓動它,似乎不工作了。

這是我檢索到的pm2錯誤日誌。沒有代碼被改變,所以我認爲這可能是一些ECONNRESET錯誤從突然關機? (沒有任何清理代碼)

也試圖殺死pm2和mongod的pid,當我找到它時使用ps -efpm2 kill和重新啓動mongod無濟於事。

Error: Invalid mongodb uri. Must begin with "mongodb://" 
    Received: NaN 
    at muri (/home/ubuntu/portal/node_modules/muri/lib/index.js:28:11) 
    at NativeConnection.Connection.openUri (/home/ubuntu/portal/node_modules/mongoose/lib/connection.js:713:18) 
    at Mongoose.createConnection (/home/ubuntu/portal/node_modules/mongoose/lib/index.js:198:17) 
    at Object.<anonymous> (/home/ubuntu/portal/models/stopwords.js:11:19) 
    at Module._compile (module.js:573:30) 
    at Object.Module._extensions..js (module.js:584:10) 
    at Module.load (module.js:507:32) 
    at tryModuleLoad (module.js:470:12) 
    at Function.Module._load (module.js:462:3) 
    at Module.require (module.js:517:17) 
    at require (internal/module.js:11:18) 
    at Object.<anonymous> (/home/ubuntu/portal/helpers/database/helper_mongodb.js:2:19) 
    at Module._compile (module.js:573:30) 
    at Object.Module._extensions..js (module.js:584:10) 
    at Module.load (module.js:507:32) 
    at tryModuleLoad (module.js:470:12) 
    at Function.Module._load (module.js:462:3) 
    at Module.require (module.js:517:17) 
    at require (internal/module.js:11:18) 
    at Object.<anonymous> (/home/ubuntu/portal/controllers/inf_controller.js:2:19) 
    at Module._compile (module.js:573:30) 
    at Object.Module._extensions..js (module.js:584:10) 

代碼stopwords.js:11:19

let db = mongoose.createConnection(process.env.MONGODB_URI + process.env.MONGODB_HELPER_DB, { useMongoClient: true }) 
+0

發現我正在從process.env.MONGODB_URI中讀取的環境變量現在返回undefined ..在這裏相當丟失爲什麼會在使用pm2後刪除 –

+0

正在運行'node app.js'工作,但不是在開始使用'pm2 start app.js --env production'或'pm2 start app.js' –

+0

您應該創建一個配置文件,也許 –

回答

0

當我們評論,和你一樣,我也用PM2 +咕嚕運行我express.js的應用程序解決了我的問題。將嘗試在這裏解釋解決問題的方法。

地開始和不同的應用程序和無故障 停止PM2的方式是有可能與我配置我節點應用一個生態系統文件(CentOS的阿帕奇)

我的生態系統文件

-bash-4.2$ pm2 ecosystem 
File /var/www/vhosts/domain.com/ecosystem.config.js 
[...] 
-bash-4.2$ cat ecosystem.config.js 
module.exports = { 
    /** 
    * Application configuration section 
    * http://pm2.keymetrics.io/docs/usage/application-declaration/ 
    */ 
    apps : [ 
    // First application 
    { 
     name  : 'DomainProd', 
     cwd  : '/var/www/vhosts/domain.com/httpdocs/App', 
     script : 'start.sh' 
    }, 
    { 
     name  : 'DomainTest', 
     cwd  : '/var/www/vhosts/domain.com/testing.domain.com/httpdocs/App', 
     script : 'start-test.sh' 
    } 
    ] 
}; 

中的start.sh腳本

-bash-4.2$ cat /var/www/vhosts/domain.com/httpdocs/App/start.sh 
/usr/bin/grunt serve:prod 
-bash-4.2$ 

我Gruntfile

return grunt.task.run(['concurrent:cleanandbuild', 'build', 'env:all', 'env:prod', 'express:prod', 'wait', 'express-keepalive']); 

的服務任務運行示例:

-bash-4.2$ pm2 status 
┌────────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬────────────┬──────────┐ 
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem  │ watching │ 
├────────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼────────────┼──────────┤ 
│ DomainProd │ 0 │ fork │ 17992 │ online │ 63  │ 20D │ 0% │ 264.1 MB │ disabled │ 
│ DomainTest │ 1 │ fork │ 25526 │ online │ 295  │ 113m │ 0% │ 1.2 MB  │ disabled │ 
└────────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴────────────┴──────────┘ 
Use `pm2 show <id|name>` to get more details about an app 
-bash-4.2$ pm2 stop 1 
[PM2] Applying action stopProcessId on app [1](ids: 1) 
[PM2] [Domainest](1) ✓ 
┌────────────┬────┬──────┬───────┬─────────┬─────────┬────────┬─────┬────────────┬──────────┐ 
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem  │ watching │ 
├────────────┼────┼──────┼───────┼─────────┼─────────┼────────┼─────┼────────────┼──────────┤ 
│ DomainProd │ 0 │ fork │ 17992 │ online │ 63  │ 20D │ 0% │ 264.1 MB │ disabled │ 
│ DomainTest │ 1 │ fork │ 0  │ stopped │ 295  │ 0  │ 0% │ 0 B  │ disabled │ 
└────────────┴────┴──────┴───────┴─────────┴─────────┴────────┴─────┴────────────┴──────────┘ 
Use `pm2 show <id|name>` to get more details about an app 
-bash-4.2$ pm2 start 1 
[PM2] Applying action restartProcessId on app [1](ids: 1) 
[PM2] [DomainTest](1) ✓ 
[PM2] Process successfully started 
┌────────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬────────────┬──────────┐ 
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem  │ watching │ 
├────────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼────────────┼──────────┤ 
│ DomainProd │ 0 │ fork │ 17992 │ online │ 63  │ 20D │ 0% │ 264.1 MB │ disabled │ 
│ DomainTest │ 1 │ fork │ 29816 │ online │ 295  │ 0s  │ 0% │ 1.2 MB  │ disabled │ 
└────────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴────────────┴──────────┘ 
Use `pm2 show <id|name>` to get more details about an app 
-bash-4.2$ pm2 logs 1 
[TAILING] Tailing last 15 lines for [1] process (change the value with --lines option) 
/var/www/vhosts/domain.com/.pm2/logs/DomainTest-out-1.log last 15 lines: 
1|DomainTe |  Execution Time (2017-10-02 19:33:24 UTC+2) 
1|DomainTe |  loading tasks 579ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 92% 
1|DomainTe |  clean:server 47ms ▇▇▇▇ 7% 
1|DomainTe |  Total 632ms 
1|DomainTe | 
1|DomainTe |  Running "clean:dist" (clean) task 
1|DomainTe |  >> 5 paths cleaned. 
1|DomainTe | 
1|DomainTe |  Done, without errors. 
1|DomainTe | 
1|DomainTe | 
1|DomainTe |  Execution Time (2017-10-02 19:33:24 UTC+2) 
1|DomainTe |  loading tasks 570ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 55% 
1|DomainTe |  clean:dist  456ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 44% 
1|DomainTe |  Total 1s 

[STREAMING] Now streaming realtime logs for [1] process 

希望它可以幫助任何人到達這裏。

相關問題