Deploy

There are several options for sanic server deployment:

Every method has own benefits and disadvantages.

Running sanic servers behind nginx makes several advantages:

But this way requires more complex configuration.

Template configuration files for nginx and supervisord are presented below. For more information, you can visit sanic.

Configuration file for nginx

upstream aiohttp {
    server 127.0.0.1:5041 fail_timeout=0;
    server 127.0.0.1:5042 fail_timeout=0;
}

server {
    listen 5040;
    client_max_body_size 4G;

    server_name 127.0.0.1;

    location / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_redirect off;
      proxy_buffering off;
      proxy_pass http://aiohttp;
    }
}

Configuration file for systemd

config should be located in directory /etc/systemd/system/

[Unit]
Description=Luna Events on port %i
After=network.target

[Service]
Restart=always
RestartSec=5
User=luna
Group=luna
SyslogIdentifier=luna-events-%i
WorkingDirectory=/var/lib/luna/current/luna-events/luna_events
# Run from luna-configurator
ExecStart=/var/lib/luna/current/luna-events/venv/bin/python ./run.py --port=%i --workers=1 --config-reload=0 --luna-config=http://127.0.0.1:5070/1 --log_suffix=%i
# Run from config file
# ExecStart=/var/lib/luna/current/luna-events/venv/bin/python ./run.py --port=%i --workers=1 --config-reload=0 --config=./configs/config.conf --log_suffix=%i


[Install]
WantedBy=multi-user.target

Start 2 instances on ports 5001, 5002:

sudo systemctl start luna-events\@{5001..5002}.service