summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-06-18 16:08:46 +0200
committerGitHub <noreply@github.com>2026-06-18 16:08:46 +0200
commitabb323b83b55f0929151d96f5d98dbd3741a55eb (patch)
treef40ecdad56ef1fd474cb0cf7c7170f2c2fc59ffc
parentd91e7ce6673d8bce86ff1143fd4c9ca8fd768ecf (diff)
parent101924e2c40f45fc1302633f2448bccee0c9c5e8 (diff)
downloadvyos-1x-abb323b83b55f0929151d96f5d98dbd3741a55eb.tar.gz
vyos-1x-abb323b83b55f0929151d96f5d98dbd3741a55eb.zip
Merge pull request #5276 from c-po/certbot-exception-handling
pki: T8994: add graceful error handling in case certbot fails
-rwxr-xr-xsrc/conf_mode/pki.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/conf_mode/pki.py b/src/conf_mode/pki.py
index 356a8dd89..349abb6fc 100755
--- a/src/conf_mode/pki.py
+++ b/src/conf_mode/pki.py
@@ -167,6 +167,7 @@ def certbot_renew(config: dict, force: bool=False) -> None:
# Determine services using ACME based certificates
pre_hook_services = []
+ stop_services = []
for used_by, _ in dict_search_recursive(config, 'used_by'):
pre_hook_services.extend(used_by)
# Remove duplicate items from list
@@ -174,16 +175,21 @@ def certbot_renew(config: dict, force: bool=False) -> None:
# Automatically add services in use to pre_hook_services depending on service
# name in vyos.defaults.systemd_services
if pre_hook_services:
- services = []
for service in pre_hook_services:
if service in systemd_services:
- services.append(systemd_services[service])
- tmp += ' --pre-hook "systemctl stop ' + ' '.join(services) + '"'
+ stop_services.append(systemd_services[service])
+ tmp += ' --pre-hook "systemctl stop ' + ' '.join(stop_services) + '"'
if force:
tmp += ' --force-renewal'
- print(cmd(tmp, raising=ConfigError, message=f'Certbot renew failed!'))
+ try:
+ print(cmd(tmp, raising=ConfigError, message=f'Certbot renew failed!'))
+ except ConfigError as e:
+ print(e)
+ for service in stop_services:
+ print(f'Restarting "{service}" with non-renewed certificate...')
+ cmd(f'systemctl restart {service}')
return None
def get_config(config=None):