diff --git a/copy-cert.json b/copy-cert.json index d6f17c1..b663b33 100644 --- a/copy-cert.json +++ b/copy-cert.json @@ -12,7 +12,8 @@ }, "owner": "user", "group": "group", - "perm": "600" + "perm": "600", + "service": "example.service" } ] } diff --git a/copy-cert.py b/copy-cert.py index e1ee1bd..317c4b7 100644 --- a/copy-cert.py +++ b/copy-cert.py @@ -4,6 +4,7 @@ import json import logging import os import shutil +import subprocess import sys import urllib3 @@ -40,6 +41,7 @@ class CertEntry: self.owner: str = d['owner'] self.group: str = d['group'] self.perm: int = int(d['perm'], base=8) + self.service: str = d['service'] class Config: def __init__(self, d: Dict): @@ -65,6 +67,7 @@ def copyFile(src: str, dst: str): logger.info('Copying file: {} --> {}'.format(src, dst)) shutil.copyfile(src, dst) + def copyCert(entry: CertEntry): copyFile(entry.priv.src, entry.priv.dst) copyFile(entry.cert.src, entry.cert.dst) @@ -75,6 +78,9 @@ def copyCert(entry: CertEntry): os.chmod(entry.priv.dst, entry.perm) os.chmod(entry.cert.dst, entry.perm) + if entry.service is not None and entry.service != '': + subprocess.run(['systemctl', 'reload-or-restart', entry.service]) + def notifyError(cert_idx: int, ntfy_endpoint: str, error_msg: str): if ('' == ntfy_endpoint): return