diff --git a/src/common/core/letsencrypt/jobs/certbot-auth.py b/src/common/core/letsencrypt/jobs/certbot-auth.py index 91d223340..61da4842e 100755 --- a/src/common/core/letsencrypt/jobs/certbot-auth.py +++ b/src/common/core/letsencrypt/jobs/certbot-auth.py @@ -30,14 +30,20 @@ try: # Get env vars bw_integration = "Linux" integration_path = Path(sep, "usr", "share", "bunkerweb", "INTEGRATION") - if getenv("KUBERNETES_MODE") == "yes": + os_release_path = Path(sep, "etc", "os-release") + if getenv("KUBERNETES_MODE", "no") == "yes": bw_integration = "Kubernetes" - elif getenv("SWARM_MODE") == "yes": + elif getenv("SWARM_MODE", "no") == "yes": bw_integration = "Swarm" - elif getenv("AUTOCONF_MODE") == "yes": + elif getenv("AUTOCONF_MODE", "no") == "yes": bw_integration = "Autoconf" elif integration_path.is_file(): - integration = integration_path.read_text(encoding="utf-8").strip() + bw_integration = integration_path.read_text(encoding="utf-8").strip() + elif os_release_path.is_file() and "Alpine" in os_release_path.read_text( + encoding="utf-8" + ): + bw_integration = "Docker" + token = getenv("CERTBOT_TOKEN", "") validation = getenv("CERTBOT_VALIDATION", "") diff --git a/src/common/core/letsencrypt/jobs/certbot-cleanup.py b/src/common/core/letsencrypt/jobs/certbot-cleanup.py index 50f1ccc24..c41ea6733 100755 --- a/src/common/core/letsencrypt/jobs/certbot-cleanup.py +++ b/src/common/core/letsencrypt/jobs/certbot-cleanup.py @@ -30,14 +30,20 @@ try: # Get env vars bw_integration = "Linux" integration_path = Path(sep, "usr", "share", "bunkerweb", "INTEGRATION") - if getenv("KUBERNETES_MODE") == "yes": + os_release_path = Path(sep, "etc", "os-release") + if getenv("KUBERNETES_MODE", "no") == "yes": bw_integration = "Kubernetes" - elif getenv("SWARM_MODE") == "yes": + elif getenv("SWARM_MODE", "no") == "yes": bw_integration = "Swarm" - elif getenv("AUTOCONF_MODE") == "yes": + elif getenv("AUTOCONF_MODE", "no") == "yes": bw_integration = "Autoconf" elif integration_path.is_file(): - integration = integration_path.read_text(encoding="utf-8").strip() + bw_integration = integration_path.read_text(encoding="utf-8").strip() + elif os_release_path.is_file() and "Alpine" in os_release_path.read_text( + encoding="utf-8" + ): + bw_integration = "Docker" + token = getenv("CERTBOT_TOKEN", "") # Cluster case diff --git a/src/common/core/letsencrypt/jobs/certbot-deploy.py b/src/common/core/letsencrypt/jobs/certbot-deploy.py index 7eae4b8d9..f9bbf48d6 100755 --- a/src/common/core/letsencrypt/jobs/certbot-deploy.py +++ b/src/common/core/letsencrypt/jobs/certbot-deploy.py @@ -33,14 +33,20 @@ try: # Get env vars bw_integration = "Linux" integration_path = Path(sep, "usr", "share", "bunkerweb", "INTEGRATION") - if getenv("KUBERNETES_MODE") == "yes": + os_release_path = Path(sep, "etc", "os-release") + if getenv("KUBERNETES_MODE", "no") == "yes": bw_integration = "Kubernetes" - elif getenv("SWARM_MODE") == "yes": + elif getenv("SWARM_MODE", "no") == "yes": bw_integration = "Swarm" - elif getenv("AUTOCONF_MODE") == "yes": + elif getenv("AUTOCONF_MODE", "no") == "yes": bw_integration = "Autoconf" elif integration_path.is_file(): - integration = integration_path.read_text(encoding="utf-8").strip() + bw_integration = integration_path.read_text(encoding="utf-8").strip() + elif os_release_path.is_file() and "Alpine" in os_release_path.read_text( + encoding="utf-8" + ): + bw_integration = "Docker" + token = getenv("CERTBOT_TOKEN", "") logger.info(f"Certificates renewal for {getenv('RENEWED_DOMAINS')} successful") diff --git a/src/common/core/letsencrypt/jobs/certbot-new.py b/src/common/core/letsencrypt/jobs/certbot-new.py index df699674a..ba0011c08 100755 --- a/src/common/core/letsencrypt/jobs/certbot-new.py +++ b/src/common/core/letsencrypt/jobs/certbot-new.py @@ -147,10 +147,10 @@ try: certbot_new(domains, real_email, letsencrypt_path, letsencrypt_job_path) != 0 ): - status = 2 logger.error( f"Certificate generation failed for domain(s) {domains} ...", ) + _exit(2) else: status = 1 logger.info( diff --git a/src/common/core/letsencrypt/jobs/certbot-renew.py b/src/common/core/letsencrypt/jobs/certbot-renew.py index 93aee1429..9cc6d90f7 100755 --- a/src/common/core/letsencrypt/jobs/certbot-renew.py +++ b/src/common/core/letsencrypt/jobs/certbot-renew.py @@ -32,11 +32,11 @@ def renew(domain: str, letsencrypt_path: Path) -> int: join(sep, "usr", "share", "bunkerweb", "deps", "python", "bin", "certbot"), "renew", "--config-dir", - letsencrypt_path.joinpath("etc"), + str(letsencrypt_path.joinpath("etc")), "--work-dir", - letsencrypt_path.joinpath("lib"), + str(letsencrypt_path.joinpath("lib")), "--logs-dir", - letsencrypt_path.joinpath("log"), + str(letsencrypt_path.joinpath("log")), "--cert-name", domain, "--deploy-hook", @@ -53,7 +53,8 @@ def renew(domain: str, letsencrypt_path: Path) -> int: ], stdin=DEVNULL, stderr=STDOUT, - env=environ, + env=environ.copy() + | {"PYTHONPATH": join(sep, "usr", "share", "bunkerweb", "deps", "python")}, check=False, ).returncode