]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Use systemd service manager notification
authorChristian Hesse <mail@eworm.de>
Thu, 1 Dec 2016 21:31:03 +0000 (22:31 +0100)
committerDavid Sommerseth <davids@openvpn.net>
Thu, 1 Dec 2016 22:45:50 +0000 (23:45 +0100)
Notify systemd service manager when our initialization sequence
completed. This helps ordering services as dependencies can rely on vpn
being available.

v2: Add curly brackets (and indention) to block the else-part, msg()
    call was non-conditional before.

v3: Move systemd header include from init.h to init.c.

Signed-off-by: Christian Hesse <mail@eworm.de>
Tested-By: Richard Bonhomme <fragmentux@gmail.com>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20161201213104.5667-1-list@eworm.de>
URL: http://www.mail-archive.com/search?l=mid&q=20161201213104.5667-1-list@eworm.de
Signed-off-by: David Sommerseth <davids@openvpn.net>
distro/systemd/openvpn-client@.service
distro/systemd/openvpn-server@.service
src/openvpn/init.c

index 18b84dd1c9aefcc08ec24fed4cb06f8d74c0f444..f64a2396574b8dcdcfbfd7888cce50a099d74453 100644 (file)
@@ -7,6 +7,7 @@ Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
 Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
 
 [Service]
+Type=notify
 PrivateTmp=true
 RuntimeDirectory=openvpn-client
 RuntimeDirectoryMode=0710
index a2b7b52b85b65cbed9e127c78d5a3cf6b7ab41e3..890e6a9ff2dfc7344fb75253a6425859097a4910 100644 (file)
@@ -7,6 +7,7 @@ Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
 Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
 
 [Service]
+Type=notify
 PrivateTmp=true
 RuntimeDirectory=openvpn-server
 RuntimeDirectoryMode=0710
index 2ccbab2f7881a997d9f5e9e81b40a50ff9f2a642..f99c934bf4efeb94c9ef68b380be3e3316dc0fa0 100644 (file)
 
 #include "syshead.h"
 
+#ifdef ENABLE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
 #include "win32.h"
 #include "init.h"
 #include "sig.h"
@@ -1251,11 +1255,19 @@ initialization_sequence_completed (struct context *c, const unsigned int flags)
       show_adapters (M_INFO|M_NOPREFIX);
       msg (M_INFO, "%s With Errors ( see http://openvpn.net/faq.html#dhcpclientserv )", message);
 #else
+#ifdef ENABLE_SYSTEMD
+      sd_notifyf(0, "STATUS=Failed to start up: %s With Errors\nERRNO=1", message);
+#endif /* HAVE_SYSTEMD_SD_DAEMON_H */
       msg (M_INFO, "%s With Errors", message);
 #endif
     }
   else
-    msg (M_INFO, "%s", message);
+    {
+#ifdef ENABLE_SYSTEMD
+      sd_notifyf(0, "READY=1\nSTATUS=%s\nMAINPID=%lu", message, (unsigned long) getpid());
+#endif
+      msg (M_INFO, "%s", message);
+    }
 
   /* Flag that we initialized */
   if ((flags & (ISC_ERRORS|ISC_SERVER)) == 0)