From 729c401c33fe97856dd4651a6796865adbe9e937 Mon Sep 17 00:00:00 2001 From: Dmitrii Iurco Date: Sun, 26 Apr 2026 09:25:02 -0400 Subject: [PATCH] fix: apply_config bootstraps wg0.conf when file is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If wg0.conf exists but is empty or has no [Interface] section, apply_config previously found no lines to update and silently returned with no changes — leaving the container broken on next restart with an empty config. Fix: detect empty/missing [Interface] section and regenerate the full config from generate_config() before applying field updates. This was the root cause of port changes not propagating: apply_config was called but found nothing to patch in an empty file. Co-Authored-By: Claude Sonnet 4.6 --- api/wireguard_manager.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/wireguard_manager.py b/api/wireguard_manager.py index 7a06789..abc5d12 100644 --- a/api/wireguard_manager.py +++ b/api/wireguard_manager.py @@ -216,7 +216,16 @@ class WireGuardManager(BaseServiceManager): return {'restarted': restarted, 'warnings': warnings} try: with open(cf) as f: - lines = f.readlines() + raw = f.read() + + # Bootstrap from generate_config() if file is empty or has no [Interface] + if not raw.strip() or '[Interface]' not in raw: + raw = self.generate_config() + with open(cf, 'w') as f: + f.write(raw) + warnings.append('wg0.conf was empty — regenerated from keys') + + lines = raw.splitlines(keepends=True) def _set_iface_field(lines, key, value): result = []