fix(deploy): sync systemd unit, preflight DB check, health retry
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+30
-5
@@ -82,19 +82,44 @@ if [ -f "${APP_ROOT}/frontend/package.json" ]; then
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
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}"
|
||||
systemctl daemon-reload 2>/dev/null || true
|
||||
systemctl restart "${SERVICE_NAME}"
|
||||
systemctl is-active --quiet "${SERVICE_NAME}" || die "${SERVICE_NAME} не active"
|
||||
|
||||
sleep 1
|
||||
if curl -sf "http://127.0.0.1:8000/health" >/dev/null 2>&1; then
|
||||
HEALTH_OK=0
|
||||
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)"
|
||||
else
|
||||
log "WARN: локальный /health не ответил — проверьте journalctl -u ${SERVICE_NAME}"
|
||||
die "${SERVICE_NAME} запущен, но /health не ответил — journalctl -u ${SERVICE_NAME} -n 80 --no-pager"
|
||||
fi
|
||||
|
||||
log "Готово."
|
||||
|
||||
Reference in New Issue
Block a user