B Robster
B Robster

Reputation: 42003

Heroku: Run different webserver process on staging site?

I want to run a different webserver on one of my staging sites, which provides more debug-friendly error handling. I'm wondering if/how this is possible without having to change the Procfile between my staging and production deployments.

I tried this:

web: newrelic-admin run-program python manage.py run_gunicorn -b 0.0.0.0:$PORT -w 4 -k gevent 
debug: newrelic-admin run-program python manage.py runserver_plus 0.0.0.0:$PORT --threaded

And then scaling web to 0 and debug to 1, but its now clear to me from this article that web is a special reserved keyword and that's the only process that gets http requests. So is there any way to manage this without having to maintain a separate branch or the like?

Upvotes: 4

Views: 677

Answers (2)

Jon Mountjoy
Jon Mountjoy

Reputation: 4526

Sure you can.

As you note, you need to use the "web" process type.

Remember that process types are effectively just named commands: "Each process type is a declaration of a command that is executed when a dyno of that process type is started"

You control the command.

In a little test app, I just created a bin directory, added a file, and gave it execute permission - like this:

mkdir bin
vi bin/go.sh
chmod a+x bin/go.sh

The contents looked like this:

echo $*
echo $FOOBAR
thin --rackup config.ru start $*

I then modified my Procfile to look like this:

web: ~/bin/go.sh --port $PORT

I also added a config var to my app:

heroku config:add FOOBAR=123

I then looked at the logs after starting

2013-03-14T11:49:42+00:00 heroku[web.1]: Starting process with command `~/bin/go.sh --port 47302` 2013-03-14T11:49:43+00:00 app[web.1]: --port 47302 2013-03-14T11:49:43+00:00 app[web.1]: 123 2013-03-14T11:49:44+00:00 heroku[web.1]: State changed from starting to up

Excellent. Can you see what happened?

  • When I started a web dyno, Heroku looked up the web process type and executed the command
  • The command started my server, but before that, it printed both the parameters sent to it (--port XXX) and the FOOBAR environment variable (which will get set by the config var)

So I think that's all you need. Just go write a bash script that, depending on a config var, executes a different command on staging vs production. On staging, set the config var. On production, don't.

Upvotes: 6

catsby
catsby

Reputation: 11342

You can create a separate Heroku app to serve as your staging environment and use the same codebase (local git repo). See Managing Multiple Environments for an App

Note that the specific task you're asking about involves changing the Procfile, so you may want to use a branch. In that case, you push branches like so (assuming multiple env as per the guide above):

$ git push heroku-staging <branch_name>:master --app staging_app_name

Upvotes: 1

Related Questions