diff --git a/usr/lib/python3.8/vmmgr/vmmgr.py b/usr/lib/python3.8/vmmgr/vmmgr.py index 989ff25..f79045f 100644 --- a/usr/lib/python3.8/vmmgr/vmmgr.py +++ b/usr/lib/python3.8/vmmgr/vmmgr.py @@ -102,14 +102,17 @@ def create_selfsigned_cert(): def request_acme_cert(): # Remove all possible conflicting certificates requested in the past domain = config.get_host()['domain'] - certs = [i for i in os.listdir(paths.ACME_DIR) if i not in ('account.conf', 'ca', 'http.header')] - for cert in certs: - if cert != domain: - subprocess.run(['/usr/bin/acme.sh', '--home', paths.ACME_DIR, '--remove', '-d', cert]) + try: + certs = [i for i in os.listdir(paths.ACME_DIR) if i not in ('account.conf', 'ca', 'http.header')] + for cert in certs: + if cert != domain: + subprocess.run(['/usr/bin/acme.sh', '--home', paths.ACME_DIR, '--remove', '-d', cert]) + except FileNotFoundError: + pass # Compile an acme.sh command for certificate requisition only if the certificate hasn't been requested before if not os.path.exists(os.path.join(paths.ACME_DIR, domain)): - cmd = ['/usr/bin/acme.sh', '--issue', '-d', domain] - for app,definition in config.get_apps(): + cmd = ['/usr/bin/acme.sh', '--home', paths.ACME_DIR, '--issue', '-d', domain] + for app,definition in config.get_apps().items(): cmd += ['-d', f'{definition["host"]}.{domain}'] cmd += ['-w', paths.ACME_DIR] # Request the certificate @@ -123,7 +126,7 @@ def request_acme_cert(): if e.returncode != 2: raise # Install the issued certificate - subprocess.run(['/usr/bin/acme.sh', '--home', paths.ACME_DIR, '--install-cert', '-d', domain, '--key-file', crypto.CERT_KEY_FILE, '--fullchain-file', crypto.CERT_PUB_FILE, '--reloadcmd', '/sbin/service nginx reload'], check=True) + subprocess.run(['/usr/bin/acme.sh', '--home', paths.ACME_DIR, '--install-cert', '-d', domain, '--key-file', paths.CERT_KEY_FILE, '--fullchain-file', paths.CERT_PUB_FILE, '--reloadcmd', '/sbin/service nginx reload'], check=True) # Enable acme.sh cronjob os.chmod(paths.ACME_CRON, 0o750)