[dm-devel] [PATCH 07/13] multipathd: use sd_notify() to inform systemd

Hannes Reinecke hare at suse.de
Fri Nov 15 10:29:38 UTC 2013


Implement sd_notify() to inform systemd about our internal state.
And we should be using the service type 'notify' so the systemd
doesn't try to flood multipathd if it's still in discovery.

Signed-off-by: Hannes Reinecke <hare at suse.de>
---
 multipathd/main.c             | 7 ++++++-
 multipathd/multipathd.service | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/multipathd/main.c b/multipathd/main.c
index 91d7bfc..b4146fd 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -17,6 +17,7 @@
 #include <limits.h>
 #include <linux/oom.h>
 #include <libudev.h>
+#include <systemd/sd-daemon.h>
 #include <semaphore.h>
 #include <mpath_persist.h>
 
@@ -1604,7 +1605,7 @@ child (void * param)
 	}
 
 	running_state = DAEMON_START;
-
+	sd_notify(0, "STATUS=startup");
 	condlog(2, "--------start up--------");
 	condlog(2, "read " DEFAULT_CONFIGFILE);
 
@@ -1672,6 +1673,7 @@ child (void * param)
 	/*
 	 * fetch and configure both paths and multipaths
 	 */
+	sd_notify(0, "STATUS=configure");
 	running_state = DAEMON_CONFIGURE;
 
 	lock(vecs->lock);
@@ -1700,11 +1702,14 @@ child (void * param)
 	/* Ignore errors, we can live without */
 
 	running_state = DAEMON_RUNNING;
+	sd_notify(0, "READY=1\nSTATUS=running");
 
 	/*
 	 * exit path
 	 */
 	while(sem_wait(&exit_sem) != 0); /* Do nothing */
+
+	sd_notify(0, "STATUS=shutdown");
 	running_state = DAEMON_SHUTDOWN;
 	lock(vecs->lock);
 	if (conf->queue_without_daemon == QUE_NO_DAEMON_OFF)
diff --git a/multipathd/multipathd.service b/multipathd/multipathd.service
index bc62bc5..03b4270 100644
--- a/multipathd/multipathd.service
+++ b/multipathd/multipathd.service
@@ -6,9 +6,10 @@ DefaultDependencies=no
 Conflicts=shutdown.target
 
 [Service]
+Type=notify
+NotifyAccess=main
 ExecStart=/sbin/multipathd -d
 ExecReload=/sbin/multipathd reconfigure
-ExecStop=/sbin/multipathd shutdown
 
 [Install]
 WantedBy=sysinit.target
-- 
1.8.1.4




More information about the dm-devel mailing list