fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 5s

This commit is contained in:
Egor Matveev 2025-06-01 14:42:31 +03:00
parent 0f4e509639
commit 8a64bec6fe

17
main.py
View File

@ -28,9 +28,22 @@ def get_hosts() -> list[str]:
def update_host(host: str):
gen_cert = call(f"docker exec $(docker ps -q -f name=infra_nginx) certbot --nginx --email emmtvv@gmail.com --agree-tos -d \"{host}\"")
if gen_cert.code != 0:
print("failed generating certificate")
print(f"failed generating certificate: {gen_cert.err}")
return
fullchain_command = call(f"docker exec $(docker ps -q -f name=infra_nginx) cat /etc/letsencrypt/live/{host}/fullchain.pem")
if fullchain_command.code != 0:
print(f"failed getting fullchain: {fullchain_command.err}")
return
privkey_command = call(f"docker exec $(docker ps -q -f name=infra_nginx) cat /etc/letsencrypt/live/{host}/privkey.pem")
if privkey_command.code != 0:
print(f"failed getting fullchain: {privkey_command.err}")
return
fullchain = fullchain_command.out.encode("utf-8")
privkey = privkey_command.out.encode("utf-8")
minio.put_object("certupdater", f"certificates/{host}/fullchain.pem", fullchain, len(fullchain))
minio.put_object("certupdater", f"certificates/{host}/privkey.pem", privkey, len(privkey))
while True:
@ -40,5 +53,5 @@ while True:
if now + datetime.timedelta(days=14) > mongo_hosts.get(host, {"expire_time": datetime.datetime.fromtimestamp(1)})["expire_time"]:
update_host(host)
print(f"Host {host} updated")
minio.put_object("certupdater", "nginx.conf", )
mongo.update_date(host)
time.sleep(5 * 60)