Deploy¶
There are several options for sanic deployment:
Standalone server
Running a pool of backend servers behind Nginx, HAProxy or another reverse proxy server.
Running sanic servers behind Nginx makes several advantages:
At first, Nginx is the perfect frontend server. It may prevent many attacks based on malformed HTTP protocol etc.
Second, running several sanic instances behind Nginx enables you to utilize all CPU cores.
Third, Nginx serves static files much faster than built-in sanic static file support.
But this way requires more complex configuration.
Template configuration files for nginx are presented below. For more information, you can visit sanic.readthedocs.io.
Configuration file for systemd¶
Systemd file example:
[Unit]
Description=Luna-Licenses on port %i
After=network.target
[Service]
Restart=always
RestartSec=5
User=luna
Group=luna
SyslogIdentifier=luna-licenses-%i
WorkingDirectory=/var/lib/luna/current/luna-licenses/luna_licenses
# Run from luna-configurator
ExecStart=/var/lib/luna/current/luna-licenses/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-licenses/venv/bin/python ./run.py --port=%i --workers=1 --config-reload=0 --log_suffix=%i --config=./configs/config.conf
[Install]
WantedBy=multi-user.target
Systemd file must be located in directory /etc/systemd/system/.
To run services using systemd file one needs to:
Copy the systemd files to /etc/systemd/system:
sudo cp ./luna-licenses/deploy/systemd-*.service /etc/systemd/system/
Change systemd file(s) in /etc/systemd/system/ (venv, paths, etc.) if necessary
Reload daemons to apply systemd files changes:
sudo systemctl daemon-reload
Start service
Start an instance on port 5121:
sudo systemctl start luna-licenses@5121.service
Check the service status
sudo systemctl status luna-licenses@5121.service
Configuration file for Nginx¶
upstream aiohttp {
server 127.0.0.1:5119 fail_timeout=0;
server 127.0.0.1:5118 fail_timeout=0;
}
server {
listen 5120;
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;
}
}