Skip to content

VPS refactoring: ARM64 support, graceful shutdown, persistence & Discord notifications#1944

Open
aharada54914 wants to merge 5 commits intokoala73:mainfrom
aharada54914:claude/vps-refactoring-plan-7Eyff
Open

VPS refactoring: ARM64 support, graceful shutdown, persistence & Discord notifications#1944
aharada54914 wants to merge 5 commits intokoala73:mainfrom
aharada54914:claude/vps-refactoring-plan-7Eyff

Conversation

@aharada54914
Copy link

Summary

Comprehensive refactoring plan and implementation for 24/7 stable operation on Hetzner CAX21 (ARM64 Debian). Adds critical production-readiness features: ARM64 Docker builds, graceful shutdown, Redis persistence, automated service startup, Docker log rotation, and a new Discord notification system powered by Gemini AI.

Type of change

  • Refactor / code cleanup
  • New feature (Discord notifications via Gemini)
  • Infrastructure

Affected areas

  • Desktop app (Tauri) — graceful shutdown in local-api-server
  • API endpoints — structured JSON logging
  • Config / Settings — docker-compose, systemd, cron
  • Other: VPS deployment, monitoring, Discord integration

Changes

P0 — Critical (Production Readiness)

ARM64 Platform Support

  • Added platforms: [linux/arm64] to all Docker build configs in docker-compose.yml
  • Ensures images build correctly on Hetzner CAX21 (Ampere Altra ARM64 CPU)

Graceful Shutdown

  • Added SIGTERM/SIGINT handlers to src-tauri/sidecar/local-api-server.mjs
  • Prevents request loss during container restarts or updates
  • 30-second timeout before forced exit

Redis Persistence

  • Enabled RDB snapshots (--save 300 100 --save 60 1000)
  • Enabled AOF logging (--appendonly yes --appendfsync everysec)
  • Increased maxmemory from 256MB to 1GB (matches CAX21 capacity)
  • Prevents data loss on container restart

Docker Log Rotation

  • Added logging config to all services with max-size and max-file limits
  • Prevents disk fill on long-running deployments

Automatic Service Startup

  • Created docker/worldmonitor.service systemd unit
  • Ensures Docker stack starts automatically after VPS reboot

P1 — High Priority (Stability & Monitoring)

Discord Periodic Notifications (New Feature)

  • Created scripts/discord-notify.mjs — fetches 8 data categories from Redis, summarizes with Gemini 2.0 Flash, posts to Discord
  • Supports both 1-time execution (cron) and daemon mode (supervisord)
  • Fallback to OpenRouter if Gemini API unavailable
  • Rich Discord Embeds with threat level, category breakdowns, event counts
  • Configurable interval via DISCORD_NOTIFY_INTERVAL_MINUTES

Memory Management

  • Added per-service memory limits in docker-compose.yml
  • Added 2GB Swap configuration script
  • Prevents OOM killer from terminating services

Seed Script Resilience

  • Enhanced scripts/run-seeders.sh with exponential backoff retry logic (3 attempts)
  • Handles transient API failures gracefully

Firewall & Security

  • Created scripts/setup-vps.sh — automated ufw configuration
  • Opens only necessary ports (22, 80, 443, 3000)
  • Configures Docker iptables bypass fix

Health Monitoring

  • Created scripts/health-check.sh — 2-minute interval health checks
  • Supports email and Discord alerts on DEGRADED/UNHEALTHY status

Cron Automation

  • Seed updates: 30-minute interval
  • Discord notifications: 60-minute interval (configurable)
  • Health checks: 2-minute interval
  • Log rotation: weekly

P2 — Medium Priority

Structured Logging

  • Added JSON logger to local-api-server.mjs for Docker mode
  • Enables log aggregation and error filtering

Environment Variables

  • Added Discord/Gemini config to .env.example
  • Added OpenRouter fallback support

Supervisord Integration

  • Added discord-notify program to docker/supervisord.conf for daemon mode

Configuration

Required Environment Variables (for Discord notifications)


https://claude.ai/code/session_012cgux13dymqPbJMuJoWBWs

claude added 3 commits March 20, 2026 15:54
Comprehensive refactoring plan targeting the Hetzner CAX21 (ARM64/Debian/8GB)
environment. Covers 17 items across P0–P3 priority levels:

- P0: ARM64 platform declaration, graceful shutdown, Redis persistence,
  log rotation, systemd auto-start
- P1: Swap config, per-service memory limits, seed retry with backoff,
  ufw firewall, cron seeding
- P2: Structured JSON logging, health check automation, Docker Secrets
- P3: TLS via Cloudflare Proxy

https://claude.ai/code/session_012cgux13dymqPbJMuJoWBWs
Revise VPS_REFACTORING_PLAN.md to include Gemini-powered Discord
periodic notification as a P1 item (Section 7):

- New script: scripts/discord-notify.mjs
  - Fetches 8 data categories from Redis in parallel
    (earthquakes M5+, unrest HIGH, military flights HIGH,
     natural disasters, weather EXTREME/SEVERE, cyber CRITICAL,
     armed conflict, market movers ±2%)
  - Summarizes via Gemini 2.0 Flash (direct API) with
    OpenRouter fallback (google/gemini-2.5-flash)
  - Posts rich Discord Embed with color-coded threat level
  - Supports configurable interval via DISCORD_NOTIFY_INTERVAL_MINUTES
  - Runs as one-shot (cron) or daemon (--daemon flag)

- New env vars: DISCORD_WEBHOOK_URL, GEMINI_API_KEY,
  GEMINI_MODEL, DISCORD_NOTIFY_INTERVAL_MINUTES, DISCORD_NOTIFY_LANGUAGE

- Added to Week 2 roadmap alongside other P1 items
- Updated file list and status summary tables

https://claude.ai/code/session_012cgux13dymqPbJMuJoWBWs
…ation

P0 — Production-critical:
- docker-compose.yml: add linux/arm64 platform to all build sections
- docker-compose.yml: enable Redis AOF+RDB persistence, maxmemory 1GB
- docker-compose.yml: add per-service mem_limit (2g/3g/1.2g/256m)
- docker-compose.yml: add json-file log rotation (max-size/max-file)
- local-api-server.mjs: add createLogger() for structured JSON logging
  in Docker mode; plain console in desktop/sidecar mode
- local-api-server.mjs: add SIGTERM/SIGINT graceful shutdown with
  30-second force-exit safety net

P1 — Operational stability + Discord notifications:
- docker-compose.yml: add DISCORD_WEBHOOK_URL / GEMINI_API_KEY /
  GEMINI_MODEL / DISCORD_NOTIFY_INTERVAL_MINUTES / DISCORD_NOTIFY_LANGUAGE
  env vars; add OPENROUTER_API_KEY passthrough
- scripts/discord-notify.mjs (new): Redis → Gemini → Discord pipeline
  - Fetches 8 data categories in parallel from Redis
  - Filters for notable events (M5+ quakes, HIGH unrest, CRITICAL cyber, etc.)
  - Summarises with Gemini 2.0 Flash (direct API) or OpenRouter fallback
  - Posts rich colour-coded Discord Embed with per-category fields
  - One-shot mode (cron) or --daemon mode (supervisord)
  - Exits 0 when env vars unset so supervisord does not restart
- scripts/run-seeders.sh: replace single-attempt loop with run_with_retry()
  (3 attempts, exponential backoff 1s/4s)
- docker/supervisord.conf: add discord-notify program (autorestart=unexpected)
- scripts/setup-vps.sh (new): one-shot VPS bootstrap script
  (2GB swap, Docker install, ufw firewall, systemd service, cron jobs)
- docker/worldmonitor.service (new): systemd unit template with
  __REPO_DIR__ placeholder substituted by setup-vps.sh

P2 — Monitoring:
- scripts/health-check.sh (new): polls /api/health every 2 min,
  sends Discord alert and optional email on DEGRADED/UNHEALTHY/UNREACHABLE

Misc:
- .env.example: document DISCORD_WEBHOOK_URL, GEMINI_API_KEY,
  GEMINI_MODEL, DISCORD_NOTIFY_INTERVAL_MINUTES, DISCORD_NOTIFY_LANGUAGE

https://claude.ai/code/session_012cgux13dymqPbJMuJoWBWs
@vercel
Copy link

vercel bot commented Mar 20, 2026

@claude is attempting to deploy a commit to the Elie Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added the trust:caution Brin: contributor trust score caution label Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

trust:caution Brin: contributor trust score caution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants