From 15f3e19da7fb4e293f15da3d41a1ab33484d0312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Sat, 30 Dec 2017 18:56:12 +0000 Subject: [PATCH] cli: Atomic write of /etc/systemd/system/openvpn-reconnect.service --- certidude/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/certidude/cli.py b/certidude/cli.py index 21fa9e3..5b57495 100755 --- a/certidude/cli.py +++ b/certidude/cli.py @@ -451,8 +451,10 @@ def certidude_enroll(fork, renew, no_wait, kerberos, skip_self): click.echo("Re-running systemd generators for OpenVPN...") os.system("systemctl daemon-reload") if not os.path.exists("/etc/systemd/system/openvpn-reconnect.service"): - with open("/etc/systemd/system/openvpn-reconnect.service", "wb") as fh: + with open("/etc/systemd/system/openvpn-reconnect.service.part", "w") as fh: fh.write(env.get_template("client/openvpn-reconnect.service").render(context)) + os.rename("/etc/systemd/system/openvpn-reconnect.service.part", + "/etc/systemd/system/openvpn-reconnect.service") click.echo("Created /etc/systemd/system/openvpn-reconnect.service") click.echo("Starting OpenVPN...") os.system("service openvpn start")