2014-11-06 88 views
7

我正在爲我的應用程序使用angular-fullstack。我想用pm2開始我的應用程序。如何使用PM2和Grunt進行部署

Angular-fullstack啓動生產模式grunt serve:dist,它運行幾個任務,包括設置環境變量。
PM2似乎用js文件啓動應用程序。像pm2 start server.js

我的問題是:
如何使用PM2在Grunt的生產模式下啓動我的應用程序?

我知道我的主應用程序文件是server/app.js,但我不能簡單地做pm2 start server/app.js,因爲這些環境變量沒有正確設置。

+0

請看看我的答案** [這裏](http://stackoverflow.com/questions/25007130/how-to-use-grunt-gulp-with-pm2?rq = 1)** – soyuka 2014-11-06 17:43:50

+1

嗨soyuka,我注意到你的答案。但是:1.我沒有提交node_modules。 2.我無法找到咕嚕聲的輸入腳本。這個腳本似乎不起作用:'node ./node_modules/grunt/lib/grunt.js serve'。感謝您的幫助! – Wint 2014-11-07 02:02:09

回答

6

我終於得到了pm2工作與咕嚕聲。只需使用/usr/bin/grunt作爲起始腳本,pm2運行良好,參數通過args部分傳遞。
這是我的ecos.json配置文件。 (我用PM2部署)

{ 
    "apps" : [{ 
    "name"  : "myapp", 
    "script" : "/usr/bin/grunt", 
    "args"  : "['serve:dist']" 
    }], 
    "deploy" : { 
    "production" : { 
     "user" : "user-name", 
     "host" : "server-address", 
     "ref" : "origin/develop", 
     "repo" : "git-url", 
     "path" : "/opt/deploy", 
     "post-deploy" : "npm install && bower install && pm2 startOrRestart ecosystem.json --env production" 
    } 
    } 
} 
+0

我碰巧遇到了類似的問題..我使用'''grunt server'''來啓動我的應用程序..並且我希望pm2監視我所做的''grunt server''' .. could你幫助我如何實現它?還是我需要使用你給出的相同答案? – 2015-10-07 07:05:46

10

另一種方法是直接使用PM2推出咕嚕:

cd /path/to/fullstack 
pm2 start grunt --name website -- serve 
+0

太棒了,它的工作! – oshingc 2016-03-21 22:35:03