Use sdnotify to inform systemd that daemon is ready

This commit is contained in:
Honza Horák 2012-09-24 13:13:06 +02:00
parent 5a7adb5d2a
commit 48bb6f4d29
3 changed files with 91 additions and 1 deletions

81
ypbind-sdnotify.patch Normal file
View File

@ -0,0 +1,81 @@
diff -up ypbind-mt-1.36/configure.in.sdnotify ypbind-mt-1.36/configure.in
--- ypbind-mt-1.36/configure.in.sdnotify 2012-07-09 16:41:36.000000000 +0200
+++ ypbind-mt-1.36/configure.in 2012-07-12 13:28:25.221031367 +0200
@@ -103,6 +103,18 @@ JH_CHECK_XML_CATALOG([http://docbook.sou
[DocBook XSL Stylesheets], [], enable_man=no)
AM_CONDITIONAL(ENABLE_REGENERATE_MAN, test x$enable_man != xno)
+USE_SD_NOTIFY=0
+AC_SUBST(USE_SD_NOTIFY)
+AC_CHECK_LIB(systemd-daemon,sd_notify,LIBSYSTEMD_DAEMON="-lsystemd-daemon",
+ LIBSYSTEMD_DAEMON="")
+if test -n "$LIBSYSTEMD_DAEMON" ; then
+ AC_CHECK_HEADERS(systemd/sd-daemon.h)
+ if test "$ac_cv_header_systemd_sd_notify_h" = yes; then
+ USE_SD_NOTIFY=1
+ fi
+fi
+AC_SUBST(USE_SD_NOTIFY)
+AC_SUBST(LIBSYSTEMD_DAEMON)
dnl internationalization macros
AM_GNU_GETTEXT_VERSION
diff -up ypbind-mt-1.36/src/Makefile.am.sdnotify ypbind-mt-1.36/src/Makefile.am
--- ypbind-mt-1.36/src/Makefile.am.sdnotify 2009-06-15 16:30:45.000000000 +0200
+++ ypbind-mt-1.36/src/Makefile.am 2012-07-12 13:28:25.288029189 +0200
@@ -8,8 +8,9 @@ localedir = $(datadir)/locale
WARNFLAGS = @WARNFLAGS@
AM_CFLAGS = -D_REENTRANT=1 $(WARNFLAGS) -DUSE_BROADCAST=@USE_BROADCAST@ \
- -DLOCALEDIR=\"$(localedir)\" @DBUS_CFLAGS@ @GLIB_CFLAGS@
-ypbind_LDADD = ../lib/libcompat.a @LIBINTL@ @SLP_LIBS@ @DBUS_LIBS@ @GLIB_LIBS@
+ -DLOCALEDIR=\"$(localedir)\" @DBUS_CFLAGS@ @GLIB_CFLAGS@ -DUSE_SD_NOTIFY=@USE_SD_NOTIFY@
+ypbind_LDADD = ../lib/libcompat.a @LIBINTL@ @SLP_LIBS@ @DBUS_LIBS@ @GLIB_LIBS@ \
+ $(LIBSYSTEMD_DAEMON)
CLEANFILES = *~
diff -up ypbind-mt-1.36/src/ypbind-mt.c.sdnotify ypbind-mt-1.36/src/ypbind-mt.c
--- ypbind-mt-1.36/src/ypbind-mt.c.sdnotify 2012-07-11 14:02:46.000000000 +0200
+++ ypbind-mt-1.36/src/ypbind-mt.c 2012-07-12 13:57:52.479549892 +0200
@@ -49,6 +49,9 @@
#if defined(HAVE_NSS_H)
#include <nss.h>
#endif
+#if defined(HAVE_SYSTEMD_SD_DAEMON_H)
+#include <systemd/sd-daemon.h>
+#endif
#include "ypbind.h"
#include "log_msg.h"
@@ -952,6 +955,30 @@ main (int argc, char **argv)
pthread_create (&ping_thread, NULL, &test_bindings, NULL);
+#ifdef USE_SD_NOTIFY
+ {
+ /*
+ * If we use systemd as an init process we may want to give it
+ * a message, that ypbind daemon is ready to accept connections.
+ * At this time, sockets for receiving connections are already
+ * created, so we can say we're ready now.
+ */
+ int result;
+ result = sd_notifyf(0, "READY=1\n"
+ "STATUS=Processing requests...\n"
+ "MAINPID=%lu", (unsigned long) getpid());
+
+ /*
+ * Return code from sd_notifyf can be ignored, as per sd_notifyf(3).
+ * However, if we use systemd's native unit file, we need to send
+ * this message to let systemd know that daemon is ready.
+ * Thus, we want to know that the call had some issues.
+ */
+ if (result < 0)
+ log_msg ("sd_notifyf failed: %s\n", strerror(-result));
+ }
+#endif
+
svc_run ();
log_msg (LOG_ERR, _("svc_run returned."));
unlink (_YPBIND_PIDFILE);

View File

@ -5,6 +5,8 @@ After=syslog.target network.target rpcbind.service ypserv.service
Before=systemd-user-sessions.service
[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/etc/sysconfig/network
EnvironmentFile=-/etc/sysconfig/ypbind
ExecStartPre=/usr/libexec/ypbind-pre-setdomain

View File

@ -1,7 +1,7 @@
Summary: The NIS daemon which binds NIS clients to an NIS domain
Name: ypbind
Version: 1.36
Release: 5%{?dist}
Release: 6%{?dist}
License: GPLv2
Group: System Environment/Daemons
Source0: http://www.linux-nis.org/download/ypbind-mt/ypbind-mt-%{version}.tar.bz2
@ -19,6 +19,7 @@ Patch2: ypbind-mt-1.32-typo.patch
Patch3: ypbind-mt-1.32-typo2.patch
Patch4: ypbind-sigpipe.patch
Patch5: ypbind-mt-1.36-nistimeout.patch
Patch6: ypbind-sdnotify.patch
# This is for /bin/systemctl
Requires(post): systemd-units
Requires(preun): systemd-units
@ -53,6 +54,9 @@ also need to install the ypserv package to a machine on your network.
%patch3 -p1 -b .typo2
%patch4 -p1 -b .sigpipe
%patch5 -p1 -b .nistimeout
%patch6 -p1 -b .sdnotify
autoreconf
%build
%configure --enable-dbus-nm
@ -117,6 +121,9 @@ fi
%doc README NEWS COPYING
%changelog
* Mon Sep 24 2012 Honza Horak <hhorak@redhat.com> - 3:1.36-6
- Use sdnotify to inform systemd that daemon is ready
* Thu Aug 23 2012 Honza Horak <hhorak@redhat.com> - 3:1.36-5
- Enhance ypbind(8) with info about NISTIMEOUT
- Add suggestion about extending NISTIMEOUT if ypbind timeouts