Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy with PM2 and Grunt

Tags:

gruntjs

pm2

I am using angular-fullstack for my application. I want to start my apps using pm2.

Angular-fullstack starts prodcution mode by grunt serve:dist, it runs several tasks including setting environment variables.
PM2 seems to start an application with a js file. like pm2 start server.js

My question is:
How do I use PM2 to start my application in production mode with Grunt?

I know my main application file is server/app.js, but I cannot simply do pm2 start server/app.js, because those environment variables are not properly set.

like image 417
Wint Avatar asked Nov 06 '14 05:11

Wint


2 Answers

An alternative is to launch grunt directly using pm2:

cd /path/to/fullstack
pm2 start grunt --name website -- serve
like image 63
morloch Avatar answered Nov 16 '22 21:11

morloch


I finally got pm2 work with grunt. just use /usr/bin/grunt as starting script and pm2 works well, the argument is passed by the args section.
Here is my ecosystem.json config file. (I am using pm2 deploy)

{
  "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"
    }
  }
}
like image 33
Wint Avatar answered Nov 16 '22 19:11

Wint