问题
my colleague passed me a project that you run grunt serve to start. Now I'm trying to use pm2 to start the project in the background forever so I can close my command line. However, I couldn't find a right way to do it.
I've seen answers like
cd /path/to/fullstack
pm2 start grunt --name website -- serve
but I don't quite understand and I have very little knowledge regarding grunt. All I know is that grunt serve runs multiple tasks at the same time for me.
I know that if I know the base js file that creates a web server for my app such as index.js. I can just run pm2 start index.js.
I tried to run the base file with node index.js, but it gives me an error cuz I need to run babel at the same time which is done by the grunt serve.
Can anyone help me to run grunt serve command using pm2?
回答1:
I advise you to create a ecosystem file and put these configs :
script: 'grunt'
and scriptArgs: ['serve']
回答2:
For anyone wondering how to achieve this in 2019, here's the solution. Leverage PM2 and PM2's Ecosystem File.
First, create a file named ecosystem.config.js
.
Then, do something like this:
module.exports = {
apps : [{
name : 'myapp', // the name of your app
cwd : '/path/to/myapp', // the directory from which your app will be launched
script : '/usr/local/bin/grunt', // the location of grunt on your system
args : 'serve' // the grunt command
}]
};
Then, just run:
pm2 start ecosystem.config.js
来源:https://stackoverflow.com/questions/41068364/how-to-use-pm2-to-run-grunt-serve