Sync servers.json and certificates.json on every change

SQLite DB in the K8s pod is ephemeral (no PV). On pod restart,
migrate_from_json() re-reads the remote JSON files. Without syncing
back, any server/cert changes after migration would be lost.

Now every server/cert write to SQLite also writes the corresponding
JSON file to the remote host, keeping them in sync.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-02-08 11:32:29 +09:00
parent 0803d7db92
commit b86ba5d994
2 changed files with 40 additions and 6 deletions

View File

@@ -265,8 +265,9 @@ def add_server_to_config(domain: str, slot: int, ip: str, http_port: int) -> Non
ip: Server IP address
http_port: HTTP port
"""
from .db import db_add_server
from .db import db_add_server, sync_servers_json
db_add_server(domain, slot, ip, http_port)
sync_servers_json()
def remove_server_from_config(domain: str, slot: int) -> None:
@@ -276,8 +277,9 @@ def remove_server_from_config(domain: str, slot: int) -> None:
domain: Domain name
slot: Server slot to remove
"""
from .db import db_remove_server
from .db import db_remove_server, sync_servers_json
db_remove_server(domain, slot)
sync_servers_json()
def remove_domain_from_config(domain: str) -> None:
@@ -286,8 +288,9 @@ def remove_domain_from_config(domain: str) -> None:
Args:
domain: Domain name to remove
"""
from .db import db_remove_domain_servers
from .db import db_remove_domain_servers, sync_servers_json
db_remove_domain_servers(domain)
sync_servers_json()
def get_shared_domain(domain: str) -> Optional[str]:
@@ -310,8 +313,9 @@ def add_shared_domain_to_config(domain: str, shares_with: str) -> None:
domain: New domain name
shares_with: Existing domain to share pool with
"""
from .db import db_add_shared_domain
from .db import db_add_shared_domain, sync_servers_json
db_add_shared_domain(domain, shares_with)
sync_servers_json()
def get_domains_sharing_pool(pool: str) -> list[str]:
@@ -358,8 +362,9 @@ def add_cert_to_config(domain: str) -> None:
Args:
domain: Domain name to add
"""
from .db import db_add_cert
from .db import db_add_cert, sync_certs_json
db_add_cert(domain)
sync_certs_json()
def remove_cert_from_config(domain: str) -> None:
@@ -368,8 +373,9 @@ def remove_cert_from_config(domain: str) -> None:
Args:
domain: Domain name to remove
"""
from .db import db_remove_cert
from .db import db_remove_cert, sync_certs_json
db_remove_cert(domain)
sync_certs_json()
# Domain map helper functions (used by domains.py)