@@ -31,24 +31,36 @@ pip install -r requirements.txt
3131deactivate || true
3232EOSCRIPT
3333
34- # Note: Port 80 binding is handled by systemd AmbientCapabilities
35- # No need to set capabilities on the Python binary
34+ # Apply capability for port binding if needed (for systemd < 229)
35+ # Modern systemd (>= 229) uses AmbientCapabilities in the service file
36+ if [ " ${UVICORN_PORT} " -lt 1024 ]; then
37+ REAL_PYTHON=$( readlink -f " ${APP_DIR} /.venv/bin/python" )
38+ if [ -f " ${REAL_PYTHON} " ]; then
39+ echo " Applying cap_net_bind_service to ${REAL_PYTHON} ..."
40+ setcap ' cap_net_bind_service=+ep' " ${REAL_PYTHON} " || echo " Warning: Failed to set capability (may not be needed with modern systemd)"
41+ fi
42+ fi
3643
3744LOG_DIR=" ${APP_DIR} /logs"
3845mkdir -p " ${LOG_DIR} "
3946chown " ${APP_USER} :${APP_USER} " " ${LOG_DIR} "
4047chmod 755 " ${LOG_DIR} "
4148
49+ # Always kill any existing uvicorn processes to avoid port conflicts
50+ echo " Stopping any existing uvicorn processes..."
51+ pkill -f " uvicorn src.server:app" || true
52+ sleep 2
53+
4254if command -v systemctl > /dev/null 2>&1 ; then
4355 systemctl daemon-reload || true
4456 if systemctl list-unit-files | grep -q " ^${SERVICE_NAME} \.service" ; then
57+ echo " Restarting systemd service ${SERVICE_NAME} .service..."
4558 systemctl restart " ${SERVICE_NAME} .service"
4659 exit 0
4760 fi
4861fi
4962
5063echo " systemd unit ${SERVICE_NAME} .service not found or unavailable. Relaunching Uvicorn with nohup."
5164
52- pkill -f " uvicorn src.server:app" || true
5365sudo -u " ${APP_USER} " nohup " ${APP_DIR} /.venv/bin/uvicorn" src.server:app --host 0.0.0.0 --port " ${UVICORN_PORT} " \
5466 > " ${LOG_DIR} /uvicorn.log" 2>&1 &
0 commit comments