How to skip pm2 app restarts on crashes within first X time

214 Views Asked by At

I deal with some NodeJS apps with a bit special corporate policy on auto-restarting. The application cannot be auto-restarted when crashing within the first minute since startup. If it crashes that early, it should be left in the pm2 "errored" state.

If it successfully reaches that time and crashes later on, the restarts can occur. Is it something that can be achieved with pm2?

I know there are options like min_uptime or max_restarts, but I don't think I can switch off restarts only in the first X seconds?

Any ideas on the solution or workarounds?

1

There are 1 best solutions below

0
douira On

I don't think you're going to find a good solution using pm2 as it doesn't have that feature. You could try to fork pm2 and add that feature, that wouldn't be that hard to do. However, your best bet is probably to manage processes yourself using nodejs's child process functions. You could also use a system process manager like systemd or launchctl depending on your system. They have more nuanced settings and might be able to do what you need.