Pm2: Only start/restart/reload certain apps in the multi process processes.json

Created on 9 Aug 2014  路  32Comments  路  Source: Unitech/pm2

We declare multiple apps (e.g. development, staging, production apps) in the processes.json file. Now it looks like doing pm2 start processes.json will start all the apps in the JSON file. Is there a way to start/restart/reload only certain apps defined in the process.json file? Otherwise, we will need to have multiple json files (one for each app) which doesn't really make sense. Thanks!

Feature

Most helpful comment

@geoshar it's already done in latest version.

$ pm2 start ecosystem.json --only "app1,app2"

All 32 comments

pm2 start processes.json to start all the apps

pm2 start|stop|reload id|name to start, stop or restart one process,

@soyuka Thanks for the hint. So I have to do pm2 start processes.json (which starts all the apps) first before I can use pm2 start|stop|reload id|name to manage individual process, right?

I can't just do pm2 start app-name where app-name is the app name specified in the process.json. Pm2 will look for a script named app-name in the filesystem, and give me a "script not found" error.

Is it possible to just load the processes.json but not start apps and allow me to control each of them using pm2 start|stop|reload id|name afterwards? Something similar to supervisord's autostart field for each program it manages. Thanks a lot!

Nope it's not possible :/. And yes you can manage them individually.

You might want to do:

pm2 start processes.json
pm2 stop all
#everything will be stopped
pm2 list
#choose the app or id and play with them manually
pm2 restart 0
pm2 restart third

@soyuka Thanks a lot. Does my use case sound reasonable? I would love to see pm2 supports that in the future!

In the meantime, I guess I will just specify the environment vars while starting my apps with pm2, like:

NODE_ENV=staging pm2 start index.coffee --name staging

And let my node.js app handles different configs under different NODE_ENVs. Although there were issues related to this env var approach, it seems to work correctly on my end. I can start/restart/reload my apps with env var correctly loaded. Maybe it's no longer an issue?

Anyway, thanks a lot for your help! I will give it a try for some time and let you know how it goes. Also, looking forward to the monitoring dashboard. Go PM2!!

You're welcome ;).

Issues with ENV on a cluster environnement are a wontfix (see the issue you've quoted).

What you would like is to have is a pm2 load processes.json command so that they are not started but only loaded in the pm2 memory?

Yes! Or we can have another autostart parameter in the processes.json for each app. By default it is set to true and pm2 will start it when pm2 start processes.json; otherwise, pm2 won't start the app. Similar to the autostart field in the program section in supervisord. Thanks!

Use multiple json files, and... we need some way to include one json in the other.

Maybe pure-js config isn't a bad idea after all.

Not sure if this should be a separate issue, but it would be useful to be able to start a specific process within a process.json file. An "include" capability should address this.

Here's my use case: I have a process.json that lists all the processes relevant for a service. I change the setting for one of them in process.json. Now I need to restart it with these new settings. I can stop/delete the old one, but I cannot issue another 'pm2 start process.json' because it would load the other task as well.

Include would address this. Or an additional arg:

pm2 start process.json app-name

If app-name is present then only that one is started. I am going to add this latter feature and I will submit a PR when done. Would you like me to use this issue or create a new one?

Does PM2 include in its dependencies anything like underscore/lodash etc, that, to satisfy laziness, I can use to pick an app by name out of the apps array in CLI.js::startJson?

Also I am thinking of a syntax that is more like this: pm2 start processes.json --only app1.

+1

I have to create two json files just because I want to use --watch option in development. It would be great to have the ability to set options per environment (now you can do this only for env_{env}).

Btw it's very strange that pm2 start ecosystem.json --watch will override --watch on ubuntu but won't work on mac (the documentation says it should not work right?).

+1

+1 for this feature. I with to have multiple configurations in the same file: dev and production and start only dev locally. The difference between the environments are just environment variables for now, but not both applications should be started.

Anyone have a preference on the implementation? I am inclined to implement pm2 start processes.json --only app1 or some version that works with PM2 option parsing, rather than an 'include' feature.

+1 for pm2 load processes.json

+1

:+1: for pm2 load processes.json

+1

+1

any ideas/updates?

I also don't like to split the processes.json. My use case is that I define the webpack-dev-server in the processes.json which pm2 shouldn't start for production (for instance).

Would something like this work for you:?

$ pm2 restart process.json <application-name>
or
$ pm2 restart process.json --only <application-name>

Yes!

pm2 start processes.json <app-name>* would be great!

_*single or list of app-names_

Finally it's going to be

$ pm2 restart process.json --only <application-name>

It's more explicit

available in dev branch

Great, Thank you!

@Unitech is there a method of disabling an app without deleting the entry in process.json, such as for a non-paying customer?

Hmm, am I doing something wrong or did this option disappear between 10.x and 15.x?

$ pm2 --version
0.10.7
$ pm2 help | grep only
    --only                               Start only a specific process from JSON file
$ pm2 --version
0.15.7
$ pm2 help | grep only
$

Update:

Really confused now. Per the change log this feature was only introduced in 1.0.2. It's not clear why it's showing up in the help text for 0.10.7 then. I suspect some sort of pilot error at my end; I am checking.

--only does not work with rundev .
I tried rundev ecosystem.config.js --only API but not filtering

The docs are misleading imho. I frist tried: pm2 start <json> --name <name> which started all apps instead of pm2 start <json> --only <name>

--only works only for one process, would be nice an improve of this like: --only process1 process2
and maybe some regular expressions here;)

@geoshar it's already done in latest version.

$ pm2 start ecosystem.json --only "app1,app2"

This does not work with pm2 deploy. My use case is that I have some worker processes that I only want to run in certain environments. I can make the processes terminate themselves if they are not in the correct environment, but that feels like a hack.

(EDIT: nevermind, I realized I can do this by changing the post-deploy script)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

webchaz picture webchaz  路  3Comments

alexpts picture alexpts  路  3Comments

chaos-git picture chaos-git  路  3Comments

phra picture phra  路  3Comments

morfies picture morfies  路  3Comments