502 Bad Gateway

Asked by iodisciple

Hi all,

I'm on Debian 9.4 and I'm following the installation guide step by step:
https://graphite.readthedocs.io/en/latest

At this point I've installed all software and dependencies, setup the database and successfully loaded the correct schema, setup Nginx and the default webpage is accessible.

Now I think I'm stuck at this step:
https://graphite.readthedocs.io/en/latest/config-webapp.html

I'm using the nginx + gunicorn and again have followed all steps. After I reload Nginx and try to access the Webapp page, I get this error:
502 Bad Gateway
nginx/1.10.3

I suspect Gunicorn needs additional configuration but I do not know what nor does the guide provide any. Does anybody know what is wrong or what I am missing?

Thanks!

Kind regards,
iodisciple

Question information

Language:
English Edit question
Status:
Solved
For:
Graphite Edit question
Assignee:
No assignee Edit question
Solved by:
iodisciple
Solved:
Last query:
Last reply:
Revision history for this message
iodisciple (iodisciple) said :
#1

This seems to get me a couple of steps further:

# cp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/webapp/graphite/graphite_wsgi.py
# cd /opt/graphite/webapp/graphite
# gunicorn graphite_wsgi:application &

Revision history for this message
Denis Zhdanov (deniszhdanov) said :
#2

You can peek gunicorn configuration e.g. in official docker image
https://github.com/graphite-project/docker-graphite-statsd/blob/master/conf/etc/service/graphite/run

export PYTHONPATH=/opt/graphite/webapp && exec /usr/local/bin/gunicorn wsgi --workers=4 --bind=0.0.0.0:8080 --log-file=/var/log/gunicorn.log --preload --pythonpath=/opt/graphite/webapp/graphite

You also need to create config for Graphite

cp /opt/graphite/webapp/graphite/local_settings.py.example /opt/graphite/webapp/graphite/local_settings.py

Revision history for this message
iodisciple (iodisciple) said :
#3

Heh that is great. I had the config already indeed. How would you make sure this Gunicorn config is started at (re)boot?

Revision history for this message
iodisciple (iodisciple) said :
#4

Solved this as well, with your help. I'll close the ticket. This is what I did.

Created /etc/systemd/system/gunicorn.service

Put this in it:
[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/opt/graphite/webapp
ExecStart=/usr/bin/gunicorn wsgi --workers=4 --bind=0.0.0.0:8080 --log-file=/var/log/gunicorn.log --preload --pythonpath=/opt/graphite/webapp/graphite

[Install]
WantedBy=multi-user.target

Execute:
# systemctl start gunicorn
# systemctl enable gunicorn

Restart and it should be running.
# systemctl status gunicorn

Revision history for this message
Steven Pine (spine) said :
#5

Please update your documentation, this information here is absolutely required to get a 'working' installation for graphite using gunicorn.

Ideally the documentation would provide the file / text required to turn gunicorn into a service.

Revision history for this message
Denis Zhdanov (deniszhdanov) said :
#6

Gunicorn is only one of many ways how you can run Graphite, systemd is only one of many ways how you can run service. Not sure if we should prefer one way to others.
But documentation is on the github - https://github.com/graphite-project/graphite-web/blob/master/docs/admin-webapp.rst , PRs are always welcome.