简体   繁体   中英

Foreman conditional running processes

I have a foreman app with a Procfile like this

web: bundle exec rails s
custom_process: bundle exec rake custom:process
faking_custom_process: bundle exec rake custom:faking_process

And I want to run custom_process or faking custom_process depends on my needs:

foreman start # run web & custom_process
FAKING_PROCESS # run web & faking_custom_process

Yes, I know about ability of running like that foreman start -c faking_custom_process=0 , but this is more difficult than I expect, right?

There's no option in foreman to just skip a process. I think you'd need to extend your start invocation to do something different too if you want to run the other processes. Otherwise you're just telling it to run zero copies of faking_custom_process and nothing else:

foreman start -m web=1,custom_process=1,faking_custom_process=0

or for the faking version:

foreman start -m web=1,custom_process=0,faking_custom_process=1

You could of course script that so you've got two scripts running those different versions.


An alternative would be to switch faking on or off using a variable in the environment (I'm not convinced it's any easier but it's an alternative):

web: bundle exec rails d
custom_process: PROCESS=$FAKING"process" && bundle exec rake custom:$PROCESS

A normal foreman start will just run bundle exec rake custom:process .

For the faking equivalent you can do:

export FAKING="faking_"

which will mean that from then on foreman start it will call bundle exec rake custom:faking_process instead.

You can return to the normal process by clearing the FAKING variable with:

export FAKING=

You could of course encapsulate that into a shell script too.

You can use .profile to store default options for foreman start :

concurrency: web=1,custom_process=1,faking_custom_process=0

or using shortcut:

concurrency: all=1,faking_custom_process=0

And then you override this default option to switch to fake process:

foreman start -c all=1,custom_process=0

See: http://ddollar.github.io/foreman/#DEFAULT-OPTIONS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM