[Unit]
Description=ANetBBS Web Application (Gunicorn + eventlet)
After=network.target

[Service]
Type=simple
User=anetbbs
Group=anetbbs
WorkingDirectory=/opt/anetbbs
EnvironmentFile=/opt/anetbbs/.env
# Privileged ports (MSP/18, SYSTAT/11) need this capability.
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
ExecStart=/opt/anetbbs/venv/bin/gunicorn \
    --worker-class eventlet \
    -w 1 \
    --worker-connections 1000 \
    -b 0.0.0.0:5000 \
    --timeout 300 \
    --graceful-timeout 30 \
    --log-level info \
    --access-logfile /opt/anetbbs/logs/gunicorn-access.log \
    --error-logfile /opt/anetbbs/logs/gunicorn-error.log \
    deploy.wsgi_wrapper:app
# Reap the whole gunicorn process group on stop. Without this, a child
# worker can survive past the master and hold port 5000, causing the
# next start to fail with EADDRINUSE in a tight crash loop.
KillMode=mixed
TimeoutStopSec=20
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
