diff --git a/.env.example b/.env.example index 573ddc4..904291f 100644 --- a/.env.example +++ b/.env.example @@ -17,11 +17,17 @@ WG_UI_PORT=51821 # --- OPZIONALI — Limiti risorse container (SBC) --- # Decommenta e adatta alla RAM disponibile: -# 512 MB RAM → WG_MEM_LIMIT=128m -# 1 GB RAM → WG_MEM_LIMIT=256m (default) -# 2 GB+ RAM → WG_MEM_LIMIT=384m +# 512 MB RAM (RPi 3B) → WG_MEM_LIMIT=96m (reale: ~37 MB, 96 m è già doppio) +# 1 GB RAM (RPi 3B+) → WG_MEM_LIMIT=128m +# 2 GB+ RAM (RPi 4/5) → WG_MEM_LIMIT=256m (default) # Tenere WG_MEMSWAP_LIMIT = WG_MEM_LIMIT per disabilitare lo swap del container. # Su single-core (Pi Zero / Pi 1) impostare WG_CPUS=0.75. +# +# ATTENZIONE — RPi 3 con uptime lungo: il processo Node.js può crescere nel +# tempo. Con 1 GB di RAM totale e OS+Docker che occupano ~350 MB, un limite +# di 256 m lascia pochissimo margine; il kernel OOM-killa SSH prima del +# container. Usare 96-128 m e assicurarsi che lo swap host sia >= 512 MB +# (vedi CLAUDE.md §SBC per il comando). # WG_MEM_LIMIT=256m # WG_MEMSWAP_LIMIT=256m # WG_CPUS=1.0 diff --git a/CLAUDE.md b/CLAUDE.md index 8166469..8f062bd 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -60,12 +60,12 @@ Affects mostly SBC boards with custom BSP kernels, but can occur on any host whe The `wg-init` service handles this automatically: it runs `modprobe ip6_tables ip6table_nat` (with `SYS_MODULE` cap and `/lib/modules` bind-mounted read-only) before wg-easy starts. Failures are silenced (`|| true`) so the setup works on kernels where these modules are built-in or unavailable. -**Resource limits** (`docker-compose.yml`): +**Resource limits** (override via `.env`): -| Variable | Default | Purpose | +| Variable | Default | Notes | |---|---|---| -| `WG_MEM_LIMIT` | `256m` | Hard memory cap for wg-easy | -| `WG_MEMSWAP_LIMIT` | `256m` | Disables swap (swap = mem limit) | -| `WG_CPUS` | `1.0` | CPU share (1 core) | +| `WG_MEM_LIMIT` | `256m` | Hard cap for the wg-easy container | +| `WG_MEMSWAP_LIMIT` | `256m` | Keep equal to `WG_MEM_LIMIT` to disable container swap | +| `WG_CPUS` | `1.0` | `0.75` on single-core boards (Pi Zero, Pi 1) | -Lower `WG_MEM_LIMIT` to `128m` on boards with less than 1 GB RAM. Do not set it below `96m` or the Node.js runtime will OOM-kill on startup. +The limit exists to prevent Node.js from slowly growing over long uptime and triggering the host OOM-killer (symptom: SSH becomes unreachable). Do not go below `96m` or the runtime OOM-kills on startup. See README §Dispositivi a risorse limitate for per-board guidance and swap configuration. diff --git a/README.md b/README.md index 1aea150..3f5d0b3 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,32 @@ vpn/ --- +## Dispositivi a risorse limitate (SBC) + +Su board con poca RAM (≤ 1 GB) il processo Node.js di wg-easy può crescere nel tempo e far sì che il kernel OOM-killi altri processi di sistema — SSH compreso. Per evitarlo, decommenta e adatta questi valori nel tuo `.env`: + +```ini +# Board con 512 MB RAM +WG_MEM_LIMIT=96m +WG_MEMSWAP_LIMIT=96m + +# Board con 1 GB RAM +WG_MEM_LIMIT=128m +WG_MEMSWAP_LIMIT=128m +``` + +Tieni `WG_MEMSWAP_LIMIT` uguale a `WG_MEM_LIMIT` per disabilitare lo swap del container: quando il container raggiunge il limite viene riavviato da Docker invece di consumare swap di sistema. + +Assicurati anche che lo swap dell'host sia almeno 512 MB. Su Raspberry Pi OS il default è 100 MB — per aumentarlo: + +```bash +sudo dphys-swapfile swapoff +sudo sed -i 's/CONF_SWAPSIZE=100/CONF_SWAPSIZE=512/' /etc/dphys-swapfile +sudo dphys-swapfile setup && sudo dphys-swapfile swapon +``` + +--- + ## Aggiornare wg-easy Esegui mensilmente per ricevere patch di sicurezza: