fix(deploy): sync systemd unit, preflight DB check, health retry

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
PTah
2026-05-28 09:28:01 +10:00
parent e0b066f5e5
commit 4d603637e5
+30 -5
View File
@@ -82,19 +82,44 @@ if [ -f "${APP_ROOT}/frontend/package.json" ]; then
fi fi
if [ -f "${APP_ROOT}/deploy/systemd/${SERVICE_NAME}.service" ]; then if [ -f "${APP_ROOT}/deploy/systemd/${SERVICE_NAME}.service" ]; then
log "systemd unit (при необходимости скопируйте вручную в /etc/systemd/system/)" SYSTEMD_DST="/etc/systemd/system/${SERVICE_NAME}.service"
if [ ! -f "${SYSTEMD_DST}" ] || ! cmp -s "${APP_ROOT}/deploy/systemd/${SERVICE_NAME}.service" "${SYSTEMD_DST}"; then
log "Обновление systemd unit → ${SYSTEMD_DST}"
cp "${APP_ROOT}/deploy/systemd/${SERVICE_NAME}.service" "${SYSTEMD_DST}"
systemctl daemon-reload
fi
fi fi
log "Проверка DATABASE_URL (как у uvicorn через SAC_CONFIG_FILE)"
sudo -u "${APP_USER}" bash -c "
export SAC_CONFIG_FILE='${CONFIG_FILE}'
cd '${APP_ROOT}/backend'
'${VENV}/bin/python' -c \"
from sqlalchemy import create_engine, text
from app.config import get_settings
engine = create_engine(get_settings().database_url, pool_pre_ping=True)
with engine.connect() as conn:
conn.execute(text('SELECT 1'))
print('db: OK')
\"
" || die "PostgreSQL: проверьте DATABASE_URL в ${CONFIG_FILE} и systemctl status postgresql"
log "systemctl restart ${SERVICE_NAME}" log "systemctl restart ${SERVICE_NAME}"
systemctl daemon-reload 2>/dev/null || true
systemctl restart "${SERVICE_NAME}" systemctl restart "${SERVICE_NAME}"
systemctl is-active --quiet "${SERVICE_NAME}" || die "${SERVICE_NAME} не active" systemctl is-active --quiet "${SERVICE_NAME}" || die "${SERVICE_NAME} не active"
sleep 1 HEALTH_OK=0
if curl -sf "http://127.0.0.1:8000/health" >/dev/null 2>&1; then for _ in 1 2 3 4 5 6; do
sleep 2
if curl -sf "http://127.0.0.1:8000/health" >/dev/null 2>&1; then
HEALTH_OK=1
break
fi
done
if [ "${HEALTH_OK}" -eq 1 ]; then
log "health: OK (http://127.0.0.1:8000/health)" log "health: OK (http://127.0.0.1:8000/health)"
else else
log "WARN: локальный /health не ответил — проверьте journalctl -u ${SERVICE_NAME}" die "${SERVICE_NAME} запущен, но /health не ответил — journalctl -u ${SERVICE_NAME} -n 80 --no-pager"
fi fi
log "Готово." log "Готово."