feat: systemd deployment

This commit is contained in:
2026-10-24 04:04:38 +02:00
parent 026d592483
commit 5c70c38523
4 changed files with 659 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
# Prod web process: gunicorn master + uvicorn ASGI workers, behind Caddy.
#
# `systemctl reload polylan-submitter` sends HUP to the gunicorn master: it
# keeps the :7777 socket open, boots new workers on the new code, then
# gracefully stops the old ones - no downtime. See deploy/systemd/deploy.sh.
#
# Install:
# sudo cp deploy/systemd/polylan-submitter.service /etc/systemd/system/
# sudo systemctl daemon-reload
# sudo systemctl restart polylan-submitter # first switch from daphne needs a full restart
[Unit]
Description=PolyLAN submitter (gunicorn + uvicorn workers)
After=network.target
[Service]
Type=simple
User=caddy
Group=caddy
WorkingDirectory=/home/caddy/polylan-submitter/polylan_submitter
# EnvironmentFile=/home/caddy/polylan-submitter/.env
# No --preload: with it, HUP re-forks from the already imported (old) code.
# --forwarded-allow-ips replaces daphne's --proxy-headers: trust
# X-Forwarded-* only from Caddy (local here).
ExecStart=/home/caddy/polylan-submitter/.venv/bin/gunicorn polylan_submitter.asgi:application \
--worker-class uvicorn_worker.UvicornWorker \
--workers 2 \
--bind 0.0.0.0:7777 \
--graceful-timeout 20 \
--forwarded-allow-ips 127.0.0.1
ExecReload=/bin/kill -s HUP $MAINPID
# SIGTERM to the master only, it then drains its workers (graceful-timeout).
KillMode=mixed
TimeoutStopSec=30
Restart=on-failure
RestartSec=2
[Install]
WantedBy=multi-user.target