bunkerweb/core/letsencrypt/jobs/certbot-renew.py
2022-06-03 17:24:14 +02:00

50 lines
2.0 KiB
Python
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/python3
import sys, os, subprocess, traceback
sys.path.append("/opt/bunkerweb/deps/python")
sys.path.append("/opt/bunkerweb/utils")
import logger
def renew(domain) :
cmd = "/opt/bunkerweb/deps/python/bin/certbot renew --cert-name " + domain + " --deploy-hook /opt/bunkerweb/core/letsencrypt/jobs/certbot-deploy.py"
os.environ["PYTHONPATH"] = "/opt/bunkerweb/deps/python"
proc = subprocess.run(cmd.split(" "), stdin=subprocess.DEVNULL, stderr=subprocess.STDOUT, env=os.environ)
return proc.returncode
status = 0
try :
if os.getenv("MULTISITE") == "yes" :
for first_server in os.getenv("SERVER_NAME").split(" ") :
if first_server == "" :
continue
if os.getenv(first_server + "_AUTO_LETS_ENCRYPT", os.getenv("AUTO_LETS_ENCRYPT")) != "yes" :
continue
if not os.path.exists("/etc/letsencrypt/live/" + first_server + "/cert.pem") :
continue
ret = renew(first_server)
if ret != 0 :
status = 2
logger.log("LETS-ENCRYPT", "", "Certificates renewal for " + first_server + " failed")
else :
logger.log("LETS-ENCRYPT", "", "Certificates renewal for " + first_server + " successful")
elif os.getenv("AUTO_LETS_ENCRYPT") == "yes" and os.getenv("SERVER_NAME") != "" :
first_server = os.getenv("SERVER_NAME").split(" ")[0]
if os.path.exists("/etc/letsencrypt/live/" + first_server + "/cert.pem") :
ret = renew(first_server)
if ret != 0 :
status = 2
logger.log("LETS-ENCRYPT", "", "Certificates renewal for " + first_server + " failed")
else :
logger.log("LETS-ENCRYPT", "", "Certificates renewal for " + first_server + " successful")
except :
status = 2
logger.log("LETS-ENCRYPT", "", "Exception while running certbot-renew.py :")
print(traceback.format_exc())
sys.exit(status)