Stub for let's encrypt renewal script
This commit is contained in:
parent
b1861037c0
commit
f5d10eff7d
1 changed files with 67 additions and 0 deletions
67
letsencrypt_renew.py
Normal file
67
letsencrypt_renew.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from io import TextIOWrapper
|
||||
import logging
|
||||
|
||||
from sarge import run, shell_format, capture_both
|
||||
from systemd.journal import JournalHandler
|
||||
|
||||
logger = logging.getLogger("letsencrypt-renew")
|
||||
logger.propagate = False
|
||||
logger.addHandler(JournalHandler())
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
|
||||
def parse_domain_list(domainfile):
|
||||
|
||||
domains = list()
|
||||
|
||||
with open(domainfile, "r") as handle:
|
||||
|
||||
for row in handle:
|
||||
|
||||
if not row.rstrip():
|
||||
continue
|
||||
|
||||
# Ignore everything after # (comment)
|
||||
row = row.partition("#")[0]
|
||||
row = row.rstrip()
|
||||
|
||||
if not row:
|
||||
continue
|
||||
|
||||
domains.append(row)
|
||||
|
||||
if not domains:
|
||||
logger.warning("No domains found in configuration.")
|
||||
return
|
||||
|
||||
domains = [shell_format("-d {0}", domain) for domain in domains]
|
||||
|
||||
return domains
|
||||
|
||||
|
||||
def renew_domains(letsencrypt_path, domains):
|
||||
|
||||
domains = " ".join(domains)
|
||||
command = " ".join([letsencrypt_path, "certonly", domains])
|
||||
|
||||
logger.info("Renewing domain certificates...")
|
||||
process = capture_both(command)
|
||||
|
||||
for stdout in TextIOWrapper(process.stdout):
|
||||
logger.info(stdin)
|
||||
|
||||
for stderr in TextIOWrapper(process.stderr):
|
||||
logger.info(stderr)
|
||||
|
||||
if process.returncode != 0:
|
||||
logger.error("Let's Encrypt domain renewal failed.")
|
||||
return
|
||||
else:
|
||||
logger.info("Domain renewal succeeded.")
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue