Skip to content

Commit

Permalink
Add updated supervisor config files for clearer logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchrisadams committed Feb 21, 2024
1 parent 77f0208 commit cdb6e91
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
7 changes: 4 additions & 3 deletions ansible/templates/supervisor.gunicorn.conf.j2
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# {{ ansible_managed }}
# Last run: {{ template_run_date }}

[supervisord]
environment=LC_ALL='en_US.UTF-8',LANG='en_US.UTF-8'

[program:{{ supervisor_gunicorn_app }}]
directory=/var/www/{{ tgwf_domain_name }}.thegreenwebfoundation.org/current/
numprocs=1
command=bash ./run_gunicorn.sh
process_name=%(process_num)02d
autostart=true
autorestart=true
stopsignal=QUIT
user={{ supervisor_user }}
stdout_logfile=%(program_name)s_%(process_num)02d_.log
stderr_logfile=%(program_name)s_%(process_num)02d_.error.log
stdout_logfile=/var/log/supervisor/%(program_name)s_%(process_num)02d.log
stderr_logfile=/var/log/supervisor/%(program_name)s_%(process_num)02d.error.log
5 changes: 4 additions & 1 deletion ansible/templates/supervisor.worker.conf.j2
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# {{ ansible_managed }}
# Last run: {{ template_run_date }}

[supervisord]
environment=LC_ALL='en_US.UTF-8',LANG='en_US.UTF-8'

[program:{{ supervisor_worker_job }}]
directory=/var/www/{{ tgwf_domain_name }}.thegreenwebfoundation.org/current/
command=bash ./run_worker.sh
process_name=%(process_num)02d
autostart=true
autorestart=true
stopsignal=TERM
user={{ supervisor_user }}
stdout_logfile=/var/log/supervisor/%(program_name)s_%(process_num)02d.log
stderr_logfile=/var/log/supervisor/%(program_name)s_%(process_num)02d.error.log
11 changes: 11 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,14 @@ These playbooks template out new scripts that supervisor the installed process m

1. [The dramatiq guide](https://dramatiq.io/guide.html)
2. [Django Dramatiq, the pacakge we use for interfacing with dramatiq](https://github.com/Bogdanp/django_dramatiq)


## Logging

As mentioned before, we use supervisor to run our both our workers and web server processes. This means processes are restarted automatically for us, and logs are rotated for us.

## Gunicorn logging

By default, gunicorn, our web server logs at the `INFO` level. This means successful requests are not logged, and only errors (with the status code 5xx) or not found requests (4xx) show up in logs.

The logs on each app server are sent to our the Loki server on our monitoring node, accessible at https://grafana.greenweb.org. This allow for centralised querying of logs.
3 changes: 1 addition & 2 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os

# increasing workers uses more RAM, but provides a simple model for scaling up resources
workers = os.getenv("GUNICORN_WORKERS", default=8)
# increasing threads saves RAM at the cost of using more CPU
threads = 1
threads = os.getenv("GUNICORN_THREADS", default=1)

0 comments on commit cdb6e91

Please sign in to comment.