26

I have this simple Procfile

web: myapp

myapp is in the path, but the processes home directory should be ./directory/. How can I specify in the Procfile where the process is to be started?

https://github.com/ddollar/foreman/pull/101 doesn't help because it assumes, that this working directory should be the same for every process specified by the Procfile

1
  • if you are using gunicorn, this post might help you
    – JPG
    Apr 9, 2021 at 16:49

3 Answers 3

58

The shell is the answer. It's as simple as

web: sh -c 'cd ./directory/ && exec appname'
3
  • 4
    Why do you need sh -c, the quotes, and the dot & slashes? Can't you just do: web: cd directory && exec appname?
    – ma11hew28
    Jun 27, 2015 at 21:54
  • 10
    I remember the problem was that the first 'cd' will be started in its own process and after it completes, the directory it changed to will be reverted back to where foreman is running. Using 'sh' will spwan it's own environment and everything in quotes thereafter will inherit this environment.
    – JohnDoe
    Sep 23, 2015 at 7:05
  • See Igbanam - sh - c is not needed to remember the cd. Jun 20 at 17:39
15

You can chain a set of shell commands together. With the current version of Foreman, you do not need to wrap this in a shell command as in @JohnDoe's answer.

web: cd server_dir && start web_service
clk: cd clock_tower && start timers

These would start the necessary processes from their respective folders and track them independently.

2
  • I have this frontend: cd ../frontend/ && npm run client, but it is looking for package.json in the current directory not where I CD into. Dec 22, 2018 at 14:09
  • Could you rather run npm run client from the current folder instead of going into the frontend folder?
    – Igbanam
    Jan 2, 2019 at 19:08
2

An answer to "How can I specify in the Procfile where the process is to be started?"

You can tell Foreman where the application root directory meaning that this does not have to be the same place as the Procfile.

You can start Foreman with the -d option (may need to use -f to the Procfile too).

  $ foreman start -d ./directory

http://ddollar.github.io/foreman/

2
  • 2
    Yeah, but what if different processes listed in the same Procfile have different root directories?
    – ma11hew28
    Jun 27, 2015 at 21:55
  • 1
    @mattdipasquale then have a Procfile in the main directory with different lines as follow: service1: foreman start -d ./directory1\n service2: foreman start -d ./directory2
    – Maxime R.
    May 6, 2017 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.