如何使用PM2和Grunt进行部署

时间:2014-11-06 05:12:09

标签: gruntjs pm2

我正在使用angular-fullstack申请。我想用pm2启动我的应用程序。

Angular-fullstack通过grunt serve:dist启动生产模式,它运行多项任务,包括设置环境变量。
PM2似乎用js文件启动一个应用程序。比如pm2 start server.js

我的问题是:
如何使用PM2在Grunt的生产模式下启动我的应用程序?

我知道我的主应用程序文件是server/app.js,但我不能简单地执行pm2 start server/app.js,因为这些环境变量没有正确设置。

2 个答案:

答案 0 :(得分:10)

另一种方法是使用pm2直接启动grunt:

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

答案 1 :(得分:6)

我终于让pm2与grunt合作了。只需使用/usr/bin/grunt作为起始脚本,pm2运行良好,参数由args部分传递。
这是我的ecosystem.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"
    }
  }
}
相关问题