Some context: I am running a production instance of edx’s platform. This means I am dealing here with django on a nginx + gunicorn + virtualenv stack. This is managed using upstart on ubuntu 12.04.2 LTS.
Back to the main topic, in case you are trying to use gunicorn and newrelic on a somewhat similar configuration this experience I had today might be of some use.
As I said, the django service uses gunicorn as it’s WSGI Http server. To start the service I normally call: $ sudo start edxapp. This runs an upstart script that works using the next line:
The script is located at
I decided to start using new-relic to monitor this service, so I needed it to start using the new relic agent. The upstart scripts had some env variables for newrelic commented out, but setting them right did not go all the way to make me happy.
After some search, some gessing and some trial and error I got it.
In short here it is:
- Make sure you installed the new relic agent. Change your newrelic.ini as you need to and test it to be sure you got it right.
- Define the environment variable inside the upstart script:
- Use the new relic agent admin to call the gunicorn process:
exec /opt/edx/bin/newrelic-admin run-program /opt/edx/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=300 --pythonpath=/opt/wwc/edx-platform lms.wsgi
$ sudo start edxapp