> For the complete documentation index, see [llms.txt](https://public-intelligence.gitbook.io/taina-agente-ia-ogtic/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://public-intelligence.gitbook.io/taina-agente-ia-ogtic/operacion-y-monitoreo/despliegue.md).

# Operación diaria

Esta sección cubre los procedimientos de operación diaria de Taína una vez desplegada con Docker Compose.

## Comandos de operación

### Iniciar el servicio

```bash
# Desde la raíz del proyecto (donde está docker-compose.yml)
cd /home/taina/taina_ogtic

# Iniciar en segundo plano
docker compose up -d
```

### Detener el servicio

```bash
docker compose down
```

### Reiniciar el servicio

```bash
docker compose restart
```

### Reconstruir después de cambios en el código

```bash
docker compose up -d --build
```

## Monitoreo

### Ver logs en tiempo real

```bash
docker compose logs -f taina-backend
```

### Ver estado del contenedor

```bash
docker compose ps
```

### Ver consumo de recursos

```bash
docker stats taina_backend
```

### Verificar que el puerto esté activo

```bash
ss -tlnp | grep 8080
```

## Actualización del sistema

Cuando se publique una nueva versión del código:

```bash
# 1. Descargar los cambios
git pull origin main

# 2. Reconstruir y reiniciar
docker compose up -d --build

# 3. Verificar que todo funciona
docker compose logs -f taina-backend
```

Si la actualización incluye nuevos datos de servicios:

```bash
# Copiar nuevos archivos *_rag_documents.json a data/chunks/
# Luego ejecutar la ingesta
docker compose exec taina-backend python -m src.ingest --json_dir data/chunks

# Reiniciar para cargar los nuevos datos
docker compose restart
```

## Backup y recuperación

### Backup de datos

Los datos críticos que deben respaldarse son:

| Directorio                          | Contenido                            |
| ----------------------------------- | ------------------------------------ |
| `backend/data/`                     | Base de conocimiento (archivos JSON) |
| `backend/storage/`                  | ChromaDB (base de datos vectorial)   |
| `backend/.env`                      | Variables de entorno y credenciales  |
| `backend/google_bucket_config.json` | Credenciales GCP                     |
| `backend/logs/`                     | Logs del agente                      |

```bash
# Crear backup comprimido
DATE=$(date +%Y%m%d_%H%M%S)
tar -czf "backup_taina_${DATE}.tar.gz" \
  --exclude='backend/.venv' \
  --exclude='backend/__pycache__' \
  backend/data/ \
  backend/storage/ \
  backend/.env \
  backend/google_bucket_config.json \
  backend/logs/
```

### Restaurar desde backup

```bash
# 1. Detener el servicio
docker compose down

# 2. Restaurar archivos
tar -xzf backup_taina_YYYYMMDD_HHMMSS.tar.gz

# 3. Reiniciar
docker compose up -d
```

## Configuración de firewall (recomendado)

```bash
# Permitir SSH
sudo ufw allow ssh

# Permitir tráfico HTTP/HTTPS (si usas reverse proxy)
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# Activar firewall
sudo ufw --force enable

# Verificar estado
sudo ufw status
```

## Reverse proxy con Nginx (opcional)

Si necesitas exponer Taína con un dominio y HTTPS:

```bash
# Instalar Nginx y Certbot
sudo apt install -y nginx certbot python3-certbot-nginx

# Crear configuración
sudo tee /etc/nginx/sites-available/taina > /dev/null << 'EOF'
server {
    listen 80;
    server_name tu-dominio.gob.do;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }

    location /health {
        access_log off;
        return 200 "healthy\n";
        add_header Content-Type text/plain;
    }
}
EOF

# Habilitar sitio
sudo ln -s /etc/nginx/sites-available/taina /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

# Obtener certificado SSL
sudo certbot --nginx -d tu-dominio.gob.do

# Verificar renovación automática
sudo certbot renew --dry-run
```

## Logs del sistema

Los logs se almacenan en `backend/logs/` y son accesibles desde el host gracias al volumen Docker montado.

```bash
# Ver logs de aplicación
tail -f backend/logs/application.log

# Ver solo errores
tail -f backend/logs/errors.log

# Ver logs de Docker
docker compose logs --tail=100 taina-backend
```

> Consulta [Monitoreo y Health Checks](/taina-agente-ia-ogtic/operacion-y-monitoreo/monitoreo.md) para configuración avanzada de alertas y métricas.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://public-intelligence.gitbook.io/taina-agente-ia-ogtic/operacion-y-monitoreo/despliegue.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
