Skip to main content
< All Topics
Print

Infrastructure Operations

name: infrastructure-operations

description: Day-to-day operations runbook for the ITI 9-container Docker stack (n8n, Dify, Postgres, Redis, Nginx). Use when performing health checks, running backups, triaging incidents, monitoring resources, or restoring services.

Infrastructure Operations

Instructions

Operate the ITI n8n + Dify Docker stack on a daily basis. All commands assume the compose project lives at ITI/infrastructure/n8n-dify/.

Daily operations cadence:

Task Command Frequency
Health check docker compose ps Daily
Log review `docker compose logs –since 24h \ grep -i error` Daily
Backup bash backup.sh Daily
Resource check docker stats --no-stream Weekly
Image updates docker compose pull && docker compose up -d Monthly
Execution review n8n UI > Executions > filter “failed” Weekly
KB quality spot-check Dify UI > Knowledge > Retrieval Testing Weekly

Health check procedure:

  1. docker compose ps — all 9 containers must show healthy or running
  2. curl -s http://localhost:5678/healthz — n8n returns {"status":"ok"}
  3. curl -s http://localhost:3001/console/api/setup — Dify Nginx proxy responds (status < 500)
  4. redis-cli ping — returns PONG
  5. docker exec iti-postgres pg_isready -U postgres — returns “accepting connections”

Backup execution and verification:


cd ITI/infrastructure/n8n-dify
bash backup.sh
ls -la /Users/username/Cursor/Archives/n8n-db-$(date +%Y%m%d).sql
ls -la /Users/username/Cursor/Archives/dify-db-$(date +%Y%m%d).sql
ls -la /Users/username/Cursor/Archives/n8n-data-$(date +%Y%m%d).tar.gz
ls -la /Users/username/Cursor/Archives/dify-data-$(date +%Y%m%d).tar.gz

Backups auto-prune after 7 days. Verify file sizes are non-zero.

Restore from backup:


docker exec -i iti-postgres psql -U postgres -d n8n < /Users/username/Cursor/Archives/n8n-db-YYYYMMDD.sql
docker exec -i iti-postgres psql -U postgres -d dify < /Users/username/Cursor/Archives/dify-db-YYYYMMDD.sql
docker run --rm -v n8n_data:/data -v /Users/username/Cursor/Archives:/backup alpine sh -c "cd /data && tar xzf /backup/n8n-data-YYYYMMDD.tar.gz"
docker compose restart

Resource monitoring:


docker stats --no-stream > /Users/username/Cursor/Archives/docker-stats-$(date +%Y%m%d).log

Thresholds: total memory < 6 GB normal, 6-8 GB acceptable, > 8 GB investigate. Largest consumers are typically iti-postgres (~1.5 GB) and iti-dify-worker (~1.3 GB).

Log rotation:


docker compose logs --since 24h > /Users/username/Cursor/Archives/n8n-dify-logs-$(date +%Y%m%d).log

n8n execution data pruning:

  • Settings > Executions > set “Execution Data Prune Threshold” to 30 days
  • Enable “Save Successful Executions” for auditing
  • Monitor execution DB size: docker exec iti-postgres psql -U postgres -d n8n -c "SELECT pg_size_pretty(pg_database_size('n8n'))"

Dify KB re-indexing: Trigger re-indexing when retrieval quality degrades or after embedding model changes. Use Dify UI > Knowledge > select dataset > Re-index, or via API: POST /console/api/datasets/{id}/indexing-estimate.

Container restart and recovery:

  • Single service: docker compose restart
  • Full stack restart: docker compose down && docker compose up -d
  • Nuclear reset (destroys data): docker compose down -v — only after confirmed backup
  • After restart, re-run health check procedure above

Incident triage decision tree:

  1. Check docker compose ps — is the container running?
  2. If stopped: docker compose logs --tail 50 — check exit reason
  3. If running but unhealthy: check healthcheck endpoint directly
  4. If memory pressure: docker stats --no-stream — identify the consumer
  5. If disk: docker system df — prune with docker system prune
  6. If n8n webhooks return 500: check n8n Executions for error details
  7. If Dify 502: restart dify-api and dify-nginx

Key file paths:

  • Compose file: ITI/infrastructure/n8n-dify/docker-compose.yml
  • Environment: ITI/infrastructure/n8n-dify/.env
  • Backup script: ITI/infrastructure/n8n-dify/backup.sh
  • Nginx config: ITI/infrastructure/n8n-dify/dify-nginx.conf
  • Test suite: ITI/infrastructure/n8n-dify/tests/
  • Archives: /Users/username/Cursor/Archives/
Table of Contents