From d2fc03a4f7b1ca48458bfd126185e12ef26f62ba Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Tue, 27 Jan 2026 14:20:51 +0100 Subject: [PATCH] fix(api): ovpn_rw, cleanup pki dir Sometimes the pki dir may contain rubbish, just delete it when not needed. The condition is hardly reproducible but it has been found on several existing machines. --- packages/ns-api/files/ns.ovpnrw | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/ns-api/files/ns.ovpnrw b/packages/ns-api/files/ns.ovpnrw index 3e1b48eb7..ccaca50f6 100755 --- a/packages/ns-api/files/ns.ovpnrw +++ b/packages/ns-api/files/ns.ovpnrw @@ -238,8 +238,9 @@ def add_instance(): return utils.validation_error("instance", "instance_already_exists", instance) tun = f'tunrw{next_instance}' - if os.path.isdir(f'/etc/openvpn/{instance}'): - return utils.validation_error("instance", "pki_dir_already_exists", instance) + if os.path.isdir(f'/etc/openvpn/{instance}') and instance not in instances: + # cleanup pki dir: the directory may contain rubbish on some corner cases + shutil.rmtree(f"/etc/openvpn/{instance}", ignore_errors=True) zone_link = "" fw_link = f"openvpn/{instance}"