🗝
summary refs log tree commit diff
path: root/nginx/sync.py
diff options
context:
space:
mode:
Diffstat (limited to 'nginx/sync.py')
-rw-r--r--nginx/sync.py23
1 files changed, 23 insertions, 0 deletions
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"]))