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

Jonik
  • 80,077
  • 70
  • 264
  • 372
JohnDoe
  • 2,422
  • 5
  • 29
  • 44
  • if you are using `gunicorn`, [this post](https://stackoverflow.com/questions/16416172/how-can-i-modify-procfile-to-run-gunicorn-process-in-a-non-standard-folder-on-he) might help you – JPG Apr 09 '21 at 16:49

3 Answers3

58

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

web: sh -c 'cd ./directory/ && exec appname'
mpromonet
  • 11,326
  • 43
  • 62
  • 91
JohnDoe
  • 2,422
  • 5
  • 29
  • 44
  • 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 '15 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 '15 at 07:05
  • See Igbanam - sh - c is not needed to remember the cd. – Taylored Web Sites Jun 20 '23 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.

Igbanam
  • 5,904
  • 5
  • 44
  • 68
  • 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. – Arup Rakshit Dec 22 '18 at 14:09
  • Could you rather run `npm run client` from the current folder instead of going into the frontend folder? – Igbanam Jan 02 '19 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/

robert_murray
  • 2,070
  • 17
  • 9
  • 2
    Yeah, but what if different processes listed in the same Procfile have different root directories? – ma11hew28 Jun 27 '15 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 06 '17 at 15:01