I want to use PM2 to replace a process manager we've been using in-house for a couple years, that we built on top of nodejs 0.10.x and node-forever.
PM2 has everything I need for this transition except one essential feature: the ability to configure a process to run only once and not restart automatically (ie we'd run it perhaps once a day only). All my other processes, I want to be restarted automatically, well, forever.
To be clear, the use case here would be to allow the process in question to be managed by PM2, but only to be run on demand which we'd script to happen perhaps once a day.
Perhaps I can hack that using _max_restarts=1_, but it would be far neater (and clearer to those who follow me in maintaining this code) to have an explicit _run_once_ or a _run_on_demand_ flag.
By the way, this could be extended with cron-like features ("run at 8.00am every day") but we don't really need that since we can use cron to do that.
pm2 start app.js --no-autorestart or "autorestart" : false in the JSON declaration.
npm i -g git://github.com/Unitech/PM2#development if you want to try right now, otherwise the official release is going to come tomorrow :)
:) wonderful. Thank you
It's published now ;)
https://github.com/Unitech/PM2/releases
@jshkurti Hey, is it possible to set 'autorestart':'false' with watch and still have the process run when the folder or file it's watching is updated? I'd like to run a shell script with composer install or npm install that watches a package.json or composer.json and runs install if the file is updated.
@jshkurti Is this new option also available through the API? I'm trying to use it like this:
pm2.start(pm2ConfigFile, { args: "--no-autorestart"}, (err, proc) => { ...
but PM2 still restarts my application. Perhaps I'm using 'args' incorrectly?
yeah, args here is the arguments you want to give to your process, you should just use :
pm2.start(pm2ConfigFile, { autorestart: false }, (err, proc) => {
});
can "autorestart" : false be included in one env only in app delcaration? for example,
env: {
NODE_ENV: "development",
autorestart: false
},
...
Any information on @jonathan-kosgei's question?
Most helpful comment
pm2 start app.js --no-autorestartor"autorestart" : falsein the JSON declaration.npm i -g git://github.com/Unitech/PM2#developmentif you want to try right now, otherwise the official release is going to come tomorrow :)