How to run trytond with nginx + supervisord + uwsgi

This tutorial explains How to get up and running trytond with Nginx as a reverse proxy and trytond as a backend with supervisord + uwsgi configurations.

  • The package tools as nginx, supervisord and uwsgi would be explain with a debian distribution but should be very similar with other linux distributions.
  • The domain as example would be example.tryton.org
  • The installation of trytond would not be cover on this How to. pypi installation it’s the most probably installation to a production enviroment so that would be expect to set up a uwsgi configuration.
  • IP 192.168.1.1 it’s where backend trytond is running.
  • PORT 8000 it’s where backend trytond port is running.

Set Up nginx

Install nginx package

apt install nginx

Set up a new virtualhost

  • Create a new file called example.tryton.org.conf at /etc/nginx/sites-available.
server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2; 

  server_name example.tryton.org;
  ssl_certificate /etc/letsencrypt/live/example.tryton.org/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/example.tryton.org/privkey.pem;
  ssl_protocols TLSv1.2 TLSv1.3;
  ssl_prefer_server_ciphers on;
  ssl_verify_client optional_no_ca;

  location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://192.168.1.1:8000;
  }
}

server {
  listen 80;
  listen [::]:80;

  server_name example.tryton.org;
  return 301 https://example.tryton.org$request_uri;
}
  • Create a symlink from sites-available to sites-enabled.
cd /etc/nginx/sites-enabled
ln -svf /etc/nginx/sites-available/example.tryton.org.conf .

Reload nginx service

  • Verify that yours configuration are OK.
nginx -t 
  • Reload nginx service
service nginx reload

Set Up trytond backend

Installation of trytond would not be cover on this How to, but the idea is to run a production enviroment, so pip installation would be expected.

uWSGI

The uWSGI project aims at developing a full stack for building hosting services.

Application servers (for various programming languages and protocols), proxies, process managers and monitors are all implemented using a common api and a common configuration style.

Install uwsgi

apt install uwsgi

Create a uwsgi configuration

[uwsgi]
http-socket=0.0.0.0:8000
master=true
plugins=python3
wsgi=trytond.application:app
cheaper=4
processes=16
threads=16

Note: If we set up our trytond inside a virtualenv we should add this line to the uwsgi.conf

virtualenv=/path/to/env

Supervisord

Supervisor is a client/server system that allows its users to control a number of processes on UNIX-like operating systems.

Installation

apt install supervisor

Configuration

Create a new config file under /etc/supervisor/conf.d/ called supervisor_tryton.conf. The contents of the file should be something like

[program:trytond]
command=uwsgi --ini /path/to/uwsgi_trytond.conf
autostart=true
autorestart=true
startretries=3
numprocs=1
stopwaitsecs=10
stopsignal=INT
redirect_stderr=true
environment=
    TRYTOND_DATABASE_URI="postgresql://db_username:db_password@db_hostname:db_port"
    TRYTOND_LOGGING_CONFIG="/path/to/trytond_tog.conf",
    PYTHONOPTIMIZE="1"

Update supervisor

You need to update supervisord so reads the new configuration

supervisorctl update

start trytond daemon with supervisord

supervisorctl start trytond

Conclusion

That’s it!

You should go to https://example.tryton.org and tryton set up should be up and running!
Enjoy!

I have some issues with such tutorial which are:

  • pick arbitrary some stack of software (nginx, supervisord and uwsgi) when there are alternatives
  • it is based on specific distribution (e.g. configuration file of nginx, usage of service)
  • it will be difficult to maintain due to all the different stack used

Also I do not see who is the target audience. People who can not make such similar setup should probably be directed to using docker image (where most of this is already prepared and many tutorial exists for the extra stuff like ssl etc.).

Finally I have also an issue because it is not explained how trytond is installed but then uwsgi configuration presuppose it is system wild (which is not really recommended but virtualenv is more often preferred).