fix: apply_config bootstraps wg0.conf when file is empty

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 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 09:25:02 -04:00
parent de5ff75a2e
commit 729c401c33
+10 -1
View File
@@ -216,7 +216,16 @@ class WireGuardManager(BaseServiceManager):
return {'restarted': restarted, 'warnings': warnings} return {'restarted': restarted, 'warnings': warnings}
try: try:
with open(cf) as f: 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): def _set_iface_field(lines, key, value):
result = [] result = []