Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize gateway startup and service update time #2153

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/dstack/_internal/proxy/gateway/services/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ def write_conf(self, conf: str, conf_name: str) -> None:
sudo_rm(conf_path)
raise

@staticmethod
def run_certbot(domain: str, acme: ACMESettings) -> None:
@classmethod
def run_certbot(cls, domain: str, acme: ACMESettings) -> None:
if cls.certificate_exists(domain):
return

logger.info("Running certbot for %s", domain)

cmd = ["sudo", "timeout", "--kill-after", str(CERTBOT_2ND_TIMEOUT), str(CERTBOT_TIMEOUT)]
Expand Down Expand Up @@ -134,6 +137,11 @@ def run_certbot(domain: str, acme: ACMESettings) -> None:
if r.returncode != 0:
raise ProxyError(f"Error obtaining {domain} TLS certificate:\n{r.stderr.decode()}")

@staticmethod
def certificate_exists(domain: str) -> bool:
cmd = ["sudo", "test", "-e", f"/etc/letsencrypt/live/{domain}/fullchain.pem"]
return subprocess.run(cmd, timeout=2).returncode == 0

@staticmethod
def get_config_name(domain: str) -> str:
return f"443-{domain}.conf"
Expand Down
Loading