[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH 2/2] Startup notification by sd_notify()



Implements simple start-up status notification via the sd_notify(3)
function from the libsystemd-daemon library. This allows proper
service startup serialization by the init daemon – services depending
on DLM will be started after dlm_controld completes the initialization.

As this pulls additional dependency, the feature my by disabled on
compile time by calling 'make' with 'USE_SD_NOTIFY=no'.

Signed-off-by: Jacek Konieczny <jajcus jajcus net>
---
 dlm_controld/Makefile |    8 ++++++++
 dlm_controld/main.c   |    8 ++++++++
 init/dlm.service      |    5 +++--
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/dlm_controld/Makefile b/dlm_controld/Makefile
index f42a913..13d6339 100644
--- a/dlm_controld/Makefile
+++ b/dlm_controld/Makefile
@@ -6,6 +6,8 @@ LIBDIR=$(PREFIX)/$(LIBNUM)
 HDRDIR=$(PREFIX)/include 
 MANDIR=$(PREFIX)/share/man
 
+USE_SD_NOTIFY=yes
+
 BIN_TARGET = dlm_controld
 
 LIB_NAME = libdlmcontrol
@@ -59,6 +61,12 @@ BIN_LDFLAGS += -lpthread -lrt -lcpg -lcmap -lcfg -lquorum
 LIB_CFLAGS += $(BIN_CFLAGS)
 LIB_LDFLAGS += -Wl,-z,relro -pie
 
+ifeq ($(USE_SD_NOTIFY),yes)
+	BIN_CFLAGS += $(shell pkg-config --cflags libsystemd-daemon) \
+		      -DUSE_SD_NOTIFY
+	BIN_LDFLAGS += $(shell pkg-config --libs libsystemd-daemon)
+endif
+
 all: $(LIB_TARGET) $(BIN_TARGET)
 
 $(BIN_TARGET): $(BIN_SOURCE)
diff --git a/dlm_controld/main.c b/dlm_controld/main.c
index deda60c..d1fdb2a 100644
--- a/dlm_controld/main.c
+++ b/dlm_controld/main.c
@@ -14,6 +14,10 @@
 #include <linux/genetlink.h>
 #include <linux/dlm_netlink.h>
 
+#ifdef USE_SD_NOTIFY
+#include <systemd/sd-daemon.h>
+#endif
+
 #include "copyright.cf"
 #include "version.cf"
 
@@ -1012,6 +1016,10 @@ static void loop(void)
 	plock_fd = rv;
 	plock_ci = client_add(rv, process_plocks, NULL);
 
+#ifdef USE_SD_NOTIFY
+	sd_notify(0, "READY=1");
+#endif
+
 	for (;;) {
 		rv = poll(pollfd, client_maxi + 1, poll_timeout);
 		if (rv == -1 && errno == EINTR) {
diff --git a/init/dlm.service b/init/dlm.service
index 3c4e53e..f068c63 100644
--- a/init/dlm.service
+++ b/init/dlm.service
@@ -3,10 +3,11 @@ Description=dlm control daemon
 After=syslog.target network.target corosync.service sys-kernel-config.mount
 
 [Service]
-Type=forking
+Type=notify
+NotifyAccess=main
 EnvironmentFile=/etc/sysconfig/dlm
 ExecStartPre=/sbin/modprobe dlm 
-ExecStart=/usr/sbin/dlm_controld $DLM_CONTROLD_OPTS
+ExecStart=/usr/sbin/dlm_controld --foreground $DLM_CONTROLD_OPTS
 #ExecStopPost=/sbin/modprobe -r dlm
 
 [Install]
-- 
1.7.7.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]