Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add processes without starting them #3759

Closed
bisubus opened this issue Jul 4, 2018 · 8 comments
Closed

Add processes without starting them #3759

bisubus opened this issue Jul 4, 2018 · 8 comments

Comments

@bisubus
Copy link
Contributor

bisubus commented Jul 4, 2018

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 │ ...
@wallet77
Copy link
Contributor

wallet77 commented Jul 5, 2018

Hi @bisubus

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

@lukepighetti
Copy link

lukepighetti commented Jul 19, 2018

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.

@jeremyjbowers
Copy link

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.

@sgronblo
Copy link

sgronblo commented Mar 1, 2021

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?

@soyasoya5
Copy link

Hi, any updates on this?

@anubhab-parallel-reality

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

@ultimate-tester
Copy link
Contributor

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

@Unitech
Copy link
Owner

Unitech commented May 24, 2024

Feature landed

Update PM2 to 5.4.0

$ npm install pm2@5.4.0 -g
$ pm2 update

@Unitech Unitech closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants