From 809608c7ef4801f80adbd0ae07301e39c11e3951 Mon Sep 17 00:00:00 2001 From: mia Date: Sun, 30 Jun 2024 18:29:59 -0700 Subject: initial commit --- nginx/sync.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 nginx/sync.py (limited to 'nginx/sync.py') diff --git a/nginx/sync.py b/nginx/sync.py new file mode 100644 index 0000000..8387e99 --- /dev/null +++ b/nginx/sync.py @@ -0,0 +1,23 @@ +from commia.prelude import * +from commia.bearer import get_key, keys +from commia.ssh import scp, ssh_args, ssh_prewarm +from commia.util import with_written + +ssh_prewarm("asylum", "secrets@bearer") + +domains = get_key(keys.domains).splitlines() + +servers = [] +server_template = Path("nginx/server.conf").read_text() +for domain in domains: + servers.append(server_template.replace("%HOST%", domain)) +servers_indented = "\n".join( + map(lambda line: f"\t{line}", "\n".join(servers).splitlines()) +).strip() + +config = Path("nginx/nginx.conf").read_text().replace("%SERVERS%", servers_indented) + +with_written(config, lambda path: scp(path, "callosum:/etc/nginx/nginx.conf")) + +if run(p([*ssh_args(), "nginx", "-t"])).returncode == 0: + run_check(p([*ssh_args(), "systemctl", "restart", "nginx"])) -- cgit 1.4.1