[ypserv] Use sdnotify to inform systemd that daemons are ready

Honza Horak hhorak at fedoraproject.org
Mon Sep 3 06:52:41 UTC 2012


commit 8641dff69b803c62c98d8be56ffdfc5846abd684
Author: Honza HorĂ¡k <hhorak at redhat.com>
Date:   Mon Sep 3 08:51:56 2012 +0200

    Use sdnotify to inform systemd that daemons are ready

 yppasswdd.service          |    2 +
 ypserv-2.29-sdnotify.patch |  171 ++++++++++++++++++++++++++++++++++++++++++++
 ypserv.service             |    2 +
 ypserv.spec                |    3 +
 ypxfrd.service             |    2 +
 5 files changed, 180 insertions(+), 0 deletions(-)
---
diff --git a/yppasswdd.service b/yppasswdd.service
index 583afbc..69d4a68 100644
--- a/yppasswdd.service
+++ b/yppasswdd.service
@@ -4,6 +4,8 @@ Requires=rpcbind.service
 After=syslog.target network.target rpcbind.service
 
 [Service]
+Type=notify
+NotifyAccess=all
 EnvironmentFile=-/etc/sysconfig/network
 EnvironmentFile=-/etc/sysconfig/yppasswdd
 ExecStartPre=/usr/libexec/yppasswdd-pre-setdomain
diff --git a/ypserv-2.29-sdnotify.patch b/ypserv-2.29-sdnotify.patch
new file mode 100644
index 0000000..fcff3f0
--- /dev/null
+++ b/ypserv-2.29-sdnotify.patch
@@ -0,0 +1,171 @@
+diff -up ypserv-2.28/configure.in.sdnotify ypserv-2.28/configure.in
+--- ypserv-2.28/configure.in.sdnotify	2012-07-12 14:29:03.491853939 +0200
++++ ypserv-2.28/configure.in	2012-07-12 14:29:03.505854057 +0200
+@@ -269,6 +269,19 @@ if test "$ac_cv_func_getrpcport" = no; t
+ 	             [ac_cv_func_getrpcport=yes; LIBS="-lrpcsvc $LIBS"])
+ fi
+ 
++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)
++
+ AC_CHECK_LIB(nsl,gethostbyname)
+ AC_CHECK_LIB(socket,socket)
+ AC_CHECK_LIB(resolv, res_gethostbyname, RESOLV="-lresolv", RESOLV="")
+@@ -357,7 +370,7 @@ Configuration:
+   Compiler flags:         ${CFLAGS}
+   Preprocessor:		  ${CPP}
+   Preprocessor flags:     ${CPPFLAGS}
+-  Libraries:		  ${LIBS} ${LIBDBM} ${LIBCRYPT}
++  Libraries:		  ${LIBS} ${LIBDBM} ${LIBCRYPT} ${LIBSYSTEMD_DAEMON}
+   Awk:                    ${AWK}
+   Shell:		  ${BASH}
+   NIS map dir:            ${YPMAPDIR}
+diff -up ypserv-2.28/lib/access.c.sdnotify ypserv-2.28/lib/access.c
+--- ypserv-2.28/lib/access.c.sdnotify	2011-08-31 13:40:11.000000000 +0200
++++ ypserv-2.28/lib/access.c	2012-07-12 14:29:03.505854057 +0200
+@@ -30,6 +30,9 @@
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
++#if defined(HAVE_SYSTEMD_SD_DAEMON_H)
++#include <systemd/sd-daemon.h>
++#endif
+ 
+ #include "log_msg.h"
+ #include "ypserv_conf.h"
+@@ -215,3 +218,25 @@ is_valid (struct svc_req *rqstp, const c
+ 
+   return status;
+ }
++
++/* Send a messages to systemd daemon, that inicialization of daemon
++   is finished and daemon is ready to accept connections.
++   It is a nop if we don't use systemd. */
++void
++announce_ready()
++{
++#ifdef USE_SD_NOTIFY
++  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
++}
+diff -up ypserv-2.28/lib/Makefile.am.sdnotify ypserv-2.28/lib/Makefile.am
+--- ypserv-2.28/lib/Makefile.am.sdnotify	2010-02-23 14:44:55.000000000 +0100
++++ ypserv-2.28/lib/Makefile.am	2012-07-12 14:29:03.506854065 +0200
+@@ -13,7 +13,8 @@ noinst_HEADERS = log_msg.h yp.h ypserv_c
+ 
+ rpcsvc_HEADERS = ypxfrd.x
+ 
+-DEFS = @DEFS@ -D_REENTRANT=1 -DCONFDIR=\"$(sysconfdir)\" -DUSE_SLP=@USE_SLP@
++DEFS = @DEFS@ -D_REENTRANT=1 -DCONFDIR=\"$(sysconfdir)\" -DUSE_SLP=@USE_SLP@ \
++	-DUSE_SD_NOTIFY=@USE_SD_NOTIFY@
+ INCLUDES = -I$(top_srcdir) -I$(top_builddir) -I$(srcdir)
+ AM_CFLAGS = @PIE_CFLAGS@
+ 
+diff -up ypserv-2.28/rpc.yppasswdd/Makefile.am.sdnotify ypserv-2.28/rpc.yppasswdd/Makefile.am
+--- ypserv-2.28/rpc.yppasswdd/Makefile.am.sdnotify	2006-08-02 15:05:04.000000000 +0200
++++ ypserv-2.28/rpc.yppasswdd/Makefile.am	2012-07-12 14:29:03.506854065 +0200
+@@ -24,7 +24,7 @@ sbin_PROGRAMS = rpc.yppasswdd
+ 
+ rpc_yppasswdd_SOURCES = update.c yppasswd_xdr.c yppasswdd.c
+ 
+-rpc_yppasswdd_LDADD =  @PIE_LDFLAGS@ $(LIBDBM) $(LIBCRYPT) $(top_builddir)/lib/libyp.a
++rpc_yppasswdd_LDADD =  @PIE_LDFLAGS@ $(LIBDBM) $(LIBCRYPT) $(LIBSYSTEMD_DAEMON) $(top_builddir)/lib/libyp.a
+ rpc_yppasswdd_CFLAGS = @PIE_CFLAGS@
+ 
+ if ENABLE_REGENERATE_MAN
+diff -up ypserv-2.28/rpc.yppasswdd/yppasswdd.c.sdnotify ypserv-2.28/rpc.yppasswdd/yppasswdd.c
+--- ypserv-2.28/rpc.yppasswdd/yppasswdd.c.sdnotify	2012-07-12 14:29:03.494853964 +0200
++++ ypserv-2.28/rpc.yppasswdd/yppasswdd.c	2012-07-12 14:29:03.507854073 +0200
+@@ -457,6 +457,13 @@ main (int argc, char **argv)
+       exit (1);
+     }
+ 
++  /* If we use systemd as an init system, we may want to give it 
++     a message, that this daemon is ready to accept connections.
++     At this time, sockets for receiving connections are already 
++     created, so we can say we're ready now. It is a nop if we 
++     don't use systemd. */
++  announce_ready();
++
+   /* Run the server */
+   svc_run ();
+   log_msg ("svc_run returned\n");
+diff -up ypserv-2.28/rpc.ypxfrd/Makefile.am.sdnotify ypserv-2.28/rpc.ypxfrd/Makefile.am
+--- ypserv-2.28/rpc.ypxfrd/Makefile.am.sdnotify	2012-07-12 14:29:42.795191749 +0200
++++ ypserv-2.28/rpc.ypxfrd/Makefile.am	2012-07-12 14:30:04.450388983 +0200
+@@ -22,7 +22,7 @@ sbin_PROGRAMS = rpc.ypxfrd
+ 
+ rpc_ypxfrd_SOURCES = ypxfrd.c ypxfrd_server.c ypxfrd_svc.c
+ 
+-rpc_ypxfrd_LDADD = @PIE_LDFLAGS@ $(top_builddir)/lib/libyp.a @LIBDBM@
++rpc_ypxfrd_LDADD = @PIE_LDFLAGS@ $(top_builddir)/lib/libyp.a @LIBDBM@ $(LIBSYSTEMD_DAEMON)
+ rpc_ypxfrd_CFLAGS = @PIE_CFLAGS@
+ 
+ if ENABLE_REGENERATE_MAN
+diff -up ypserv-2.28/rpc.ypxfrd/ypxfrd.c.sdnotify ypserv-2.28/rpc.ypxfrd/ypxfrd.c
+--- ypserv-2.28/rpc.ypxfrd/ypxfrd.c.sdnotify	2012-07-12 14:29:03.496853980 +0200
++++ ypserv-2.28/rpc.ypxfrd/ypxfrd.c	2012-07-12 14:29:03.508854082 +0200
+@@ -458,6 +458,13 @@ main (int argc, char **argv)
+       alarm (_RPCSVC_CLOSEDOWN);
+     }
+ 
++  /* If we use systemd as an init system, we may want to give it 
++     a message, that this daemon is ready to accept connections.
++     At this time, sockets for receiving connections are already 
++     created, so we can say we're ready now. It is a nop if we 
++     don't use systemd. */
++  announce_ready();
++
+   svc_run();
+   log_msg("svc_run returned");
+   unlink (_YPXFRD_PIDFILE);
+diff -up ypserv-2.28/ypserv/Makefile.am.sdnotify ypserv-2.28/ypserv/Makefile.am
+--- ypserv-2.28/ypserv/Makefile.am.sdnotify	2009-04-02 15:10:19.000000000 +0200
++++ ypserv-2.28/ypserv/Makefile.am	2012-07-12 14:30:15.628494608 +0200
+@@ -22,7 +22,7 @@ sbin_PROGRAMS = ypserv
+ 
+ ypserv_SOURCES = ypserv.c server.c ypserv_xdr.c reg_slp.c
+ 
+-ypserv_LDADD =  @PIE_LDFLAGS@ $(top_builddir)/lib/libyp.a @LIBDBM@ @LIBSLP@
++ypserv_LDADD =  @PIE_LDFLAGS@ $(top_builddir)/lib/libyp.a @LIBDBM@ @LIBSLP@ $(LIBSYSTEMD_DAEMON)
+ ypserv_CFLAGS = @PIE_CFLAGS@
+ 
+ if ENABLE_REGENERATE_MAN
+diff -up ypserv-2.28/ypserv/ypserv.c.sdnotify ypserv-2.28/ypserv/ypserv.c
+--- ypserv-2.28/ypserv/ypserv.c.sdnotify	2012-07-12 14:29:03.498853997 +0200
++++ ypserv-2.28/ypserv/ypserv.c	2012-07-12 14:29:03.509854091 +0200
+@@ -586,6 +586,13 @@ main (int argc, char **argv)
+     register_slp ();
+ #endif
+ 
++  /* If we use systemd as an init system, we may want to give it 
++     a message, that this daemon is ready to accept connections.
++     At this time, sockets for receiving connections are already 
++     created, so we can say we're ready now. It is a nop if we 
++     don't use systemd. */
++  announce_ready();
++
+ #if 0
+   mysvc_run ();
+ #else
diff --git a/ypserv.service b/ypserv.service
index 0868394..f6b1939 100644
--- a/ypserv.service
+++ b/ypserv.service
@@ -4,6 +4,8 @@ Requires=rpcbind.service
 After=syslog.target network.target rpcbind.service 
 
 [Service]
+Type=notify
+NotifyAccess=all
 EnvironmentFile=-/etc/sysconfig/network
 ExecStart=/usr/sbin/ypserv -f $YPSERV_ARGS
 
diff --git a/ypserv.spec b/ypserv.spec
index 1227a28..1cf70b8 100644
--- a/ypserv.spec
+++ b/ypserv.spec
@@ -32,6 +32,7 @@ Patch8: ypserv-2.24-aliases.patch
 Patch9: ypserv-2.25-systemd.patch
 Patch16: ypserv-2.27-confpost.patch
 Patch17: ypserv-2.27-cloexec.patch
+Patch18: ypserv-2.29-sdnotify.patch
 
 BuildRequires: tokyocabinet-devel
 BuildRequires: systemd-units
@@ -66,6 +67,7 @@ machines.
 %patch9 -p1 -b .systemd
 %patch16 -p1 -b .confpost
 %patch17 -p1 -b .cloexec
+%patch18 -p1 -b .sdnotify
 
 autoreconf
 
@@ -192,6 +194,7 @@ NOPUSH=true make -eC /var/yp >&2 || :
 %changelog
 * Mon Sep 03 2012 Honza Horak <hhorak at redhat.com> - 2.29-1
 - Update to new upstream version that fix memory leaks (Related: #845283)
+- Use sdnotify to inform systemd that daemons are ready
 
 * Sun Jul 22 2012 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 2.28-3
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild
diff --git a/ypxfrd.service b/ypxfrd.service
index 02bbd9d..1e62dca 100644
--- a/ypxfrd.service
+++ b/ypxfrd.service
@@ -4,6 +4,8 @@ Requires=rpcbind.service
 After=syslog.target network.target rpcbind.service
 
 [Service]
+Type=notify
+NotifyAccess=all
 EnvironmentFile=-/etc/sysconfig/network
 ExecStart=/usr/sbin/rpc.ypxfrd -f $YPXFRD_ARGS
 


More information about the scm-commits mailing list