pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

Add processes without starting them

Open bisubus opened this issue 7 years ago • 7 comments
trafficstars

This is a feature request that applies to any PM2 version.

Currently processes should be started in order to be added to process list and be referred with their names. This provides undesirable side effects when a process shouldn't be started right now.

Given apps.json configuration file with several applications:

{
    "apps": [
        "app1": ...,
        "app2": ...
    ]
}

And current process list:

│ App name                  │ id │ mode │ pid   │ status  │ ...
├───────────────────────────┼────┼──────┼───────┼─────────│ ...
│ some-other-app            │ 0  │ fork │  ...  │ online  │ ...
│ app1                      │ 1  │ fork │  ...  │ online  │ ...

pm2 restart ./apps.json adds processes from the configuration and forces their statuses to be online:

│ App name                  │ id │ mode │ pid   │ status  │ ...
├───────────────────────────┼────┼──────┼───────┼─────────│ ...
│ some-other-app            │ 0  │ fork │  ...  │ online  │ ...
│ app1                      │ 1  │ fork │  ...  │ online  │ ...
│ app2                      │ 2  │ fork │  ...  │ online  │ ...

While pm2 stop ./apps.json doesn't modify process list, only sets stopped status for known processes:

│ App name                  │ id │ mode │ pid   │ status  │ ...
├───────────────────────────┼────┼──────┼───────┼─────────│ ...
│ some-other-app            │ 0  │ fork │  ...  │ online  │ ...
│ app1                      │ 1  │ fork │  ...  │ stopped │ ...

The suggestion is to update process list from configuration file and set stopped status with pm2 stop ./apps.json (likely with additional key):

│ App name                  │ id │ mode │ pid   │ status  │ ...
├───────────────────────────┼────┼──────┼───────┼─────────│ ...
│ some-other-app            │ 0  │ fork │  ...  │ online  │ ...
│ app1                      │ 1  │ fork │  ...  │ stopped │ ...
│ app2                      │ 2  │ fork │  ...  │ stopped │ ...

And to not change process status (stopped by default) with pm2 refresh ./apps.json:

│ App name                  │ id │ mode │ pid   │ status  │ ...
├───────────────────────────┼────┼──────┼───────┼─────────│ ...
│ some-other-app            │ 0  │ fork │  ...  │ online  │ ...
│ app1                      │ 1  │ fork │  ...  │ online  │ ...
│ app2                      │ 2  │ fork │  ...  │ stopped │ ...

bisubus avatar Jul 04 '18 13:07 bisubus

Hi @bisubus

I think we need a reflection about processes list and how to manage this. It can be related to this :

  • https://github.com/Unitech/pm2/issues/3685
  • https://github.com/Unitech/pm2/issues/3678
  • https://github.com/Unitech/pm2/issues/3625
  • https://github.com/Unitech/pm2/issues/3756

wallet77 avatar Jul 05 '18 11:07 wallet77

I had created a droplet snapshot the other day with the purpose of being able to recreate it for testing some software at any time. Part of this relied on some scripts that called "pm2 start process" which had already been added to PM2, but were stopped because they required a non-pm2 process to be started first.

My solution was to crontab -e @reboot pm2 stop specificProcess

this worked fine, in all honesty, but it would have been nice to pm2 save the exact state, ie

process state
process1 running
process2 stopped
process3 running

I think this is OK because you pretty much have to explicitly stop a process for it to be stopped, as far as I know?

but then again, a one-liner in crontab functionally solved it for me, so maybe its a nonissue.

lukepighetti avatar Jul 19 '18 11:07 lukepighetti

We have several daemons that are similar (one for loading live data, one for loading test / replay data) that need to be turned on / off by users when they would like them to be running. For our purposes, it would be nice to be able to load configuration for a daemon but in the stopped state so that users could toggle them on and off at will.

jeremyjbowers avatar Aug 20 '18 16:08 jeremyjbowers

This feature would be very useful together with cron_restart. You might want to create the process but it shouldn't be run right away. It would only be run when it gets restarted by the cron_restart command. Is there any chance this feature might get implemented in the near future? Or is there any workaround for it?

sgronblo avatar Mar 01 '21 01:03 sgronblo

Hi, any updates on this?

soyasoya5 avatar Oct 10 '21 11:10 soyasoya5

This feature would be very useful together with cron_restart. You might want to create the process but it shouldn't be run right away. It would only be run when it gets restarted by the cron_restart command. Is there any chance this feature might get implemented in the near future? Or is there any workaround for it?

I am facing this same problem, when my cicd reloads all the processes in the config file, the cron also runs despite having cron_restart set, so as a workaround, I am checking the time (with sufficient buffer) inside the process also and not running the actual tasks of the process if the time is not intended

I'm going through the issues to find mentions about not auto-starting a new process, which I now created a PR for: #5780

ultimate-tester avatar Mar 08 '24 19:03 ultimate-tester

Feature landed

Update PM2 to 5.4.0

$ npm install [email protected] -g
$ pm2 update

Unitech avatar May 24 '24 12:05 Unitech