Compare commits

..

No commits in common. "1f7cef1f4bf4e159ac92dbf588214b2f60fd770e" and "6cedf34b8ed041705a79b650af2b218998cd36b7" have entirely different histories.

15
main.py
View File

@ -42,22 +42,22 @@ def update_host(host: str) -> bool:
if not container_name: if not container_name:
print("No nginx container") print("No nginx container")
return False return False
gen_command = f"docker exec {container_name} certbot --nginx --email emmtvv@gmail.com --agree-tos --non-interactive -d \"{host}\"" gen_command = f"docker exec {container_name} certbot --nginx --email emmtvv@gmail.com --agree-tos --non-interactive -d \"{host}\""
print(gen_command) print(gen_command)
gen_cert = call(gen_command) gen_cert = call(gen_command)
if gen_cert.code != 0: if gen_cert.code != 0:
print(f"failed generating certificate: {gen_cert.err}") print(f"failed generating certificate: {gen_cert.err}")
print("Here is the log") print("Here is the log")
print(call(f"docker exec {container_name} cat /var/log/letsencrypt/letsencrypt.log").out) print(call(f"docker exec {container_name} cat /var/log/letsencrypt/letsencrypt.log").out)
return False return False
fullchain_command = call(f"docker exec {container_name} cat /etc/letsencrypt/live/{host}/fullchain.pem") fullchain_command = call(f"docker exec {container_name} cat /etc/letsencrypt/live/{host}/fullchain.pem")
if fullchain_command.code != 0: if fullchain_command.code != 0:
print(f"failed getting fullchain: {fullchain_command.err}") print(f"failed getting fullchain: {fullchain_command.err}")
return True return True
privkey_command = call(f"docker exec {container_name} cat /etc/letsencrypt/live/{host}/privkey.pem") privkey_command = call(f"docker exec {container_name} cat /etc/letsencrypt/live/{host}/privkey.pem")
if privkey_command.code != 0: if privkey_command.code != 0:
print(f"failed getting fullchain: {privkey_command.err}") print(f"failed getting fullchain: {privkey_command.err}")
@ -83,9 +83,10 @@ while True:
updated = True updated = True
if updated: if updated:
if os.getenv("STAGE") == "development": if os.getenv("STAGE") == "development":
container_id_run = call(f"echo $(docker ps -q -f name=infra-development_nginx)").out container_id_run = call(f"echo $(docker ps -q -f name=infra-development_nginx)")
result = call(f"docker restart {container_id_run.out}")
else: else:
container_id_run = call(f"echo $(docker ps -q -f name=infra_nginx)").out result = call("docker service update --force infra_nginx")
print(call("docker exec {container_id_run} python3 prepare.py && nginx -s reload").out)
print(result.err, result.out)
time.sleep(30) time.sleep(30)