chore: deploy scripts + env

This commit is contained in:
2026-09-17 17:28:06 +02:00
parent 28d2a7ad24
commit 979be91417
8 changed files with 344 additions and 23 deletions
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# Deploys polylan-submitter from /opt/polylan-submitter: pulls latest master,
# syncs the venv, renders and installs the supervisor config, restarts the
# supervisor programs, installs the (static) HAProxy config, reloads
# HAProxy, then re-adds the backend servers over HAProxy's admin socket -
# a reload always resets HAProxy back to just the one static server in
# deploy/haproxy/haproxy.cfg, so the rest get added fresh every time.
#
# Run on the target host (needs sudo for cp/supervisorctl/systemctl/socat):
# deploy/deploy.sh
set -euo pipefail
APP_DIR=/opt/polylan-submitter
RUN_DIR="$APP_DIR/run"
SUPERVISOR_CONF_DIR=/etc/supervisor/conf.d
HAPROXY_CONF=/etc/haproxy/haproxy.cfg
HAPROXY_ADMIN_SOCK=/run/haproxy/admin.sock
HAPROXY_BACKEND=polylan_submitter_web
# Single source of truth for daphne process count: drives supervisor's
# numprocs, and how many backend servers get re-added to HAProxy below
# (server 00 is already static in haproxy.cfg, so only 01..N-1 are added).
NUM_WEB_WORKERS=5
cd "$APP_DIR"
git pull --ff-only
uv sync --frozen
sudo mkdir -p "$RUN_DIR"
sudo chown polylan:polylan "$RUN_DIR"
render_dir=$(mktemp -d)
trap 'rm -rf "$render_dir"' EXIT
sed "s/__NUM_WEB_WORKERS__/$NUM_WEB_WORKERS/" \
"$APP_DIR/deploy/supervisor/polylan-submitter.conf" > "$render_dir/polylan-submitter.conf"
sudo cp "$render_dir/polylan-submitter.conf" "$SUPERVISOR_CONF_DIR/polylan-submitter.conf"
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl restart polylan-submitter:
sudo mkdir -p "$(dirname "$HAPROXY_ADMIN_SOCK")"
sudo cp "$APP_DIR/deploy/haproxy/haproxy.cfg" "$HAPROXY_CONF"
sudo haproxy -c -f "$HAPROXY_CONF"
sudo systemctl reload haproxy
# The admin socket only processes one command per connection - sending
# several commands into one socat session silently drops everything after
# the first, so each command below gets its own connection.
for ((i = 1; i < NUM_WEB_WORKERS; i++)); do
printf -v socket_num "%02d" "$i"
server="${HAPROXY_BACKEND}/web-${socket_num}"
socket="unix@${RUN_DIR}/web-${socket_num}.sock"
echo "add server ${server} ${socket} check" | sudo socat - "UNIX-CONNECT:${HAPROXY_ADMIN_SOCK}"
echo "enable server ${server}" | sudo socat - "UNIX-CONNECT:${HAPROXY_ADMIN_SOCK}"
done