I need an additional process to be run in development called Proxylocal (this allows external web services to hit http endpoints on my local machine).
In order to do this reliably though I would like to add the process into my Procfile. Since the process should not be run in production I am using this technique to do the switching.
My Procfile looks like this:
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
redis: redis-server
worker: bundle exec sidekiq
proxylocal: bin/proxylocal
and bin/proxylocal
looks like this:
#!/bin/bash
if [ "$RACK_ENV" == "development" ]
then
proxylocal 5000 --host mypersonalmachine
fi
(I've never done any bash scripting so have no idea whether this is the correct syntax - I just copied it).
However each time I run foreman start
it immediately exits with only the following error:
10:57:25 proxylocal.1 | started with pid 14935
10:57:25 proxylocal.1 | exited with code 0
10:57:25 system | sending SIGTERM to all processes
Update1
If I remove the if
statement and change bin/proxylocal
to simply:
proxylocal 5000 --host mypersonalmachine
Then that does work successfully. Why then does the if
statement make everything baulk?
Update 2
The following code does work as long as $RACK_ENV is equal to "development". I had to remove the double quotes around $RACK_ENV
and to change the ==
to a single =
.
if [ $RACK_ENV = "development" ]; then
proxylocal 5000 --host brojure
fi
However... it only works as long as $RACK_ENV
does equate to 'development'. When it doesn't it chokes.
Is it because Procfile needs a process ID?
A friend suggested that the issue may be that the Procfile is expecting a process ID to be returned from the script. So in the instance when we're not on development it's got nothing to process.
Is there a way in which I could spin up a zero-overhead process just to be able to return an ID. It's ugly but probably not too costly...