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.
An alternative is to launch grunt directly using pm2:
cd /path/to/fullstack
pm2 start grunt --name website -- serve
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"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With