Pm2: How to have pm2 not auto restart process

Created on 4 Feb 2015  路  11Comments  路  Source: Unitech/pm2

Is there a way to have my process end in a way that pm2 will not restart it?

Most helpful comment

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 :)

All 11 comments

You can use max_restarts setting. See example here: https://github.com/Unitech/PM2/blob/development/ADVANCED_README.md#json-app-declaration

Is it possible to specify max_restarts any other way than a JSON application declaration? I'm trying to specify that option using pm2.start like:

pm2.start("/path/to/script", { max_restarts: 3 }, function (err, proc) {
  // ...
});

It doesn't seem to work for me. The process continuously restarts.

Indeed, max_restart concerns consecutives unstable restarts (restarts happening in less than 1sec interval between them).
max_restarts defaults to 15.
I will implement --no-restart flag soon.
I'll keep you informed ;)

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 :)

@jshkurti Is there a PR to look at?

It is not merged yet, it will be tomorrow.

And it works well! closing

@Unitech This wasn't exposed for pm.start(StartOptions)? I'm controlling pm2 from my app and the application declarations are dynamic. How can i disable autorestart?

$ pm2 --verison
v3.2.2

The only access i have to autorestart is during the callback but this doesn't work:

pm.start({
    ...,
    wait_ready: false,
    min_uptime: 100,
    max_restarts: 0,
    restart_delay: 0,
    watch: false,
}, (err: Error, proc: Proc) => {
    proc.autorestart = false
    if (err) {
        throw err
    }
})

updated

I'm using typescript and the autorestart is not in StartOptions so there's a type-mismatch when i add autorestart: false to the options passed to pm.start. But when I ignore the type-mismatch or force cast as pm2.StartOptions, it does indeed work.

So I suppose this should be reopened to add autostart?: boolean to StartOptions.

Was this page helpful?
0 / 5 - 0 ratings