Procfile start processes in their own working directory
Asked Answered
P

3

27

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

Permanency answered 8/11, 2012 at 7:19 Comment(1)
if you are using gunicorn, this post might help youRosanne
P
59

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

web: sh -c 'cd ./directory/ && exec appname'
Permanency answered 9/12, 2012 at 19:7 Comment(3)
Why do you need sh -c, the quotes, and the dot & slashes? Can't you just do: web: cd directory && exec appname?Shippy
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.Permanency
See Igbanam - sh - c is not needed to remember the cd.Disruption
I
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.

Indulgent answered 6/6, 2017 at 12:18 Comment(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.Sound
Could you rather run npm run client from the current folder instead of going into the frontend folder?Indulgent
C
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/

Cannonry answered 19/1, 2015 at 17:50 Comment(2)
Yeah, but what if different processes listed in the same Procfile have different root directories?Shippy
@mattdipasquale then have a Procfile in the main directory with different lines as follow: service1: foreman start -d ./directory1\n service2: foreman start -d ./directory2Kindhearted

© 2022 - 2024 — McMap. All rights reserved.