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"]))