OPS Center production runbook

Estado: produccion inicial endurecida

Fecha: 2026-05-05

1. Alcance

Este runbook cubre backup, restore, deploy, rollback, migraciones y checklist E2E para el VPS sa-tools.

Rutas actuales:

  • App: /var/www/ops
  • Backups: /var/backups/ops-center
  • Auth env: /etc/ops-center/auth.env
  • DB env: /etc/ops-center/db.env
  • Servicio web: ops-center.service
  • Worker dispatch: ops-dispatch-launcher.service
  • Scheduler recurrentes: ops-templates-scheduler.timer
  • API local: http://127.0.0.1:3847/api
  • API publica: https://ops.solucionesabiertas.net/api

2. Regla de oro

Antes de cada deploy:

  1. Backup local zip.
  2. Backup VPS zip de fuentes.
  3. pg_dump de ops_center.
  4. Commit y push de la rama de desarrollo.
  5. Deploy.
  6. Health + smoke.

Si una validacion falla, parar y restaurar o corregir antes de seguir.

3. Backup

Local desde el workspace:


ts=$(date +%Y%m%d_%H%M%S)

zip -qr "backups/ops-center-local-$ts.zip" . -x '.git/*' 'node_modules/*' 'backups/*' 'tmp/*'

VPS:


ts=$(date +%Y%m%d_%H%M%S)

backup_dir="/var/backups/ops-center/pre_deploy_$ts"

sudo mkdir -p "$backup_dir"

sudo python3 -m zipfile -c "$backup_dir/ops-source.zip" /var/www/ops

sudo -u postgres pg_dump ops_center | sudo tee "$backup_dir/ops-center.sql" >/dev/null

sudo ls -lah "$backup_dir"

4. Deploy manual actual

El servidor no es un checkout git. El deploy seguro es copiar artefactos versionados a tmp y luego instalar.

Ejemplo para archivos de app:


ssh sa-tools 'sudo mkdir -p /var/www/ops/tmp/deploy && sudo chown $USER:$USER /var/www/ops/tmp/deploy'

scp server.js public/index.html package.json scripts/smoke-saas-e2e.js sa-tools:/var/www/ops/tmp/deploy/

ssh sa-tools 'set -e;

  sudo install -m 0644 /var/www/ops/tmp/deploy/server.js /var/www/ops/server.js;

  sudo install -m 0644 /var/www/ops/tmp/deploy/index.html /var/www/ops/public/index.html;

  sudo install -m 0644 /var/www/ops/tmp/deploy/package.json /var/www/ops/package.json;

  sudo install -m 0755 /var/www/ops/tmp/deploy/smoke-saas-e2e.js /var/www/ops/scripts/smoke-saas-e2e.js;

  sudo systemctl restart ops-center.service;

  sudo systemctl restart ops-dispatch-launcher.service'

Si cambia package-lock.json o dependencias:


cd /var/www/ops

npm ci --omit=dev

5. Migraciones

Normal:


cd /var/www/ops

set -a

. /etc/ops-center/db.env

set +a

npm run db:migrate

Migraciones con DDL/FK si el rol app no tiene permisos suficientes:


sudo -u postgres psql -d ops_center -f migrations/NNN-name.sql

Despues insertar registro en schema_migrations solo si el runner no pudo hacerlo y el SQL ya se aplico correctamente.

6. Validacion obligatoria

Entorno:


cd /var/www/ops

set -a

. /etc/ops-center/auth.env

. /etc/ops-center/db.env

set +a

Health:


curl -fsS -H "X-OPS-Service-Token: $OPS_SERVICE_TOKEN" \

  http://127.0.0.1:3847/api/system/health

Dispatch:


curl -fsS -H "X-OPS-Service-Token: $OPS_SERVICE_TOKEN" \

  http://127.0.0.1:3847/api/dispatch/health

npm run smoke:dispatch

SaaS onboarding:


npm run smoke:saas

Readiness:


curl -fsS -H "X-OPS-Service-Token: $OPS_SERVICE_TOKEN" \

  http://127.0.0.1:3847/api/saas/readiness

Servicios:


systemctl is-active ops-center.service ops-dispatch-launcher.service ops-templates-scheduler.timer

7. Restore / rollback

Restaurar fuentes:


sudo systemctl stop ops-dispatch-launcher.service

sudo systemctl stop ops-center.service

sudo unzip -oq /var/backups/ops-center/<backup>/ops-source.zip -d /

sudo systemctl start ops-center.service

sudo systemctl start ops-dispatch-launcher.service

Restaurar DB solo si es imprescindible:


sudo systemctl stop ops-dispatch-launcher.service

sudo systemctl stop ops-center.service

sudo -u postgres dropdb ops_center

sudo -u postgres createdb ops_center

sudo -u postgres psql -d ops_center -f /var/backups/ops-center/<backup>/ops-center.sql

sudo systemctl start ops-center.service

sudo systemctl start ops-dispatch-launcher.service

Despues ejecutar validacion obligatoria completa.

8. Runtimes

Estado actual:

  • opencode: operativo.
  • codex: operativo.
  • hermes: operativo con AGENT_CMD_HERMES=/opt/hermes-agent/.venv/bin/hermes en /etc/ops-center/auth.env.
  • claudecode: inactivo hasta configurar ANTHROPIC_API_KEY o claude auth login.

Para reactivar claudecode:

  1. Configurar credencial/sesion en VPS.
  2. Ejecutar npm run worker:doctor.
  3. Activar agente en OPS.
  4. Reiniciar ops-dispatch-launcher.service.
  5. Verificar /api/dispatch/health.

9. Criterio de cierre

Un deploy queda cerrado solo si:

  • git status --short local esta limpio.
  • Commit esta pusheado.
  • Backup local y VPS existen.
  • /api/system/health devuelve ok=true.
  • /api/dispatch/health devuelve ok=true.
  • /api/saas/readiness devuelve ok=true.
  • npm run smoke:dispatch pasa.
  • npm run smoke:saas pasa.
  • Servicios systemd estan active.