How to deploy with PM2 and Grunt
Asked Answered
H

2

7

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.

Hash answered 6/11, 2014 at 5:12 Comment(2)
Please have a look at my answer hereChasseur
Hi soyuka, I noticed your answer there. but: 1. I didn't commit node_modules. 2. I cannot find the entry script for grunt. this script does not seem to work: node ./node_modules/grunt/lib/grunt.js serve . Thanks your help!Hash
H
6

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"
    }
  }
}
Hash answered 9/11, 2014 at 15:13 Comment(1)
I happen to have similar problem as yours.. I'm using grunt server to start my application.. and I want pm2 to monitor the grunt server that I made.. could you help me on how to achieve it ? or do I need to use the same answer that you give ?Vegetal
S
10

An alternative is to launch grunt directly using pm2:

cd /path/to/fullstack
pm2 start grunt --name website -- serve
Shayneshays answered 15/10, 2015 at 11:38 Comment(0)
H
6

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"
    }
  }
}
Hash answered 9/11, 2014 at 15:13 Comment(1)
I happen to have similar problem as yours.. I'm using grunt server to start my application.. and I want pm2 to monitor the grunt server that I made.. could you help me on how to achieve it ? or do I need to use the same answer that you give ?Vegetal

© 2022 - 2024 — McMap. All rights reserved.