support for sending startup notifications to systemd (#1077666)

This commit is contained in:
Jiri Popelka 2014-03-18 17:08:49 +01:00
parent 9b2a8d5429
commit 0ae0d118cb
5 changed files with 99 additions and 7 deletions

78
dhcp-sd-daemon.patch Normal file
View File

@ -0,0 +1,78 @@
diff -up dhcp-4.3.0/configure.ac.sd-daemon dhcp-4.3.0/configure.ac
--- dhcp-4.3.0/configure.ac.sd-daemon 2014-03-18 15:17:11.000000000 +0100
+++ dhcp-4.3.0/configure.ac 2014-03-18 15:35:47.982182345 +0100
@@ -677,6 +677,17 @@ if test x$ldap = xyes || test x$ldapcryp
fi
fi
+AC_ARG_WITH(systemd,
+ AC_HELP_STRING([--with-systemd],
+ [enable sending status notifications to systemd daemon (default is no)]),
+ [systemd=$withval],
+ [systemd=no])
+
+if test x$systemd = xyes ; then
+ AC_CHECK_LIB(systemd-daemon, sd_notify, ,
+ AC_MSG_FAILURE([*** sd-daemon library not present - do you need to install systemd-libs package?]))
+fi
+
# Append selected warning levels to CFLAGS before substitution (but after
# AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[],[]) & etc).
CFLAGS="$CFLAGS $STD_CWARNINGS"
diff -up dhcp-4.3.0/relay/dhcrelay.c.sd-daemon dhcp-4.3.0/relay/dhcrelay.c
--- dhcp-4.3.0/relay/dhcrelay.c.sd-daemon 2014-03-18 15:17:11.000000000 +0100
+++ dhcp-4.3.0/relay/dhcrelay.c 2014-03-18 15:35:42.063264999 +0100
@@ -36,6 +36,10 @@
int keep_capabilities = 0;
#endif
+#ifdef HAVE_LIBSYSTEMD_DAEMON
+#include <systemd/sd-daemon.h>
+#endif
+
TIME default_lease_time = 43200; /* 12 hours... */
TIME max_lease_time = 86400; /* 24 hours... */
struct tree_cache *global_options[256];
@@ -624,6 +628,14 @@ main(int argc, char **argv) {
}
#endif
+#ifdef HAVE_LIBSYSTEMD_DAEMON
+ /* We are ready to process incomming packets. Let's notify systemd */
+ sd_notifyf(0, "READY=1\n"
+ "STATUS=Dispatching packets...\n"
+ "MAINPID=%lu",
+ (unsigned long) getpid());
+#endif
+
/* Start dispatching packets and timeouts... */
dispatch();
diff -up dhcp-4.3.0/server/dhcpd.c.sd-daemon dhcp-4.3.0/server/dhcpd.c
--- dhcp-4.3.0/server/dhcpd.c.sd-daemon 2014-03-18 15:17:11.000000000 +0100
+++ dhcp-4.3.0/server/dhcpd.c 2014-03-18 15:34:59.207863458 +0100
@@ -54,6 +54,10 @@ static const char url [] =
#include "trace.h"
+#ifdef HAVE_LIBSYSTEMD_DAEMON
+#include <systemd/sd-daemon.h>
+#endif
+
#ifndef UNIT_TEST
static void usage(void);
#endif
@@ -792,6 +796,13 @@ main(int argc, char **argv) {
TRACE(DHCPD_MAIN());
+#ifdef HAVE_LIBSYSTEMD_DAEMON
+ /* We are ready to process incomming packets. Let's notify systemd */
+ sd_notifyf(0, "READY=1\n"
+ "STATUS=Dispatching packets...\n"
+ "MAINPID=%lu",
+ (unsigned long) getpid());
+#endif
/*
* Receive packets and dispatch them...
* dispatch() will never return.

View File

@ -18,7 +18,7 @@
Summary: Dynamic host configuration protocol software
Name: dhcp
Version: 4.3.0
Release: 8%{?dist}
Release: 9%{?dist}
# NEVER CHANGE THE EPOCH on this package. The previous maintainer (prior to
# dcantrell maintaining the package) made incorrect use of the epoch and
# that's why it is at 12 now. It should have never been used, but it was.
@ -79,6 +79,7 @@ Patch39: dhcp-range6.patch
Patch40: dhcp-next-server.patch
Patch41: dhcp-no-subnet-error2info.patch
Patch42: dhcp-ffff-checksum.patch
Patch43: dhcp-sd-daemon.patch
BuildRequires: autoconf
BuildRequires: automake
@ -86,7 +87,7 @@ BuildRequires: libtool
BuildRequires: openldap-devel
BuildRequires: libcap-ng-devel
BuildRequires: bind-lite-devel >= 32:9.9.5-0.1.b1
BuildRequires: systemd
BuildRequires: systemd systemd-devel
BuildRequires: doxygen
%if %sdt
BuildRequires: systemtap-sdt-devel
@ -352,6 +353,8 @@ rm -rf includes/isc-dhcp
# (Submitted to dhcp-bugs@isc.org - [ISC-Bugs #25587])
%patch42 -p1 -b .ffff
# support for sending startup notification to systemd (#1077666)
%patch43 -p1 -b .sd-daemon
# Update paths in all man pages
for page in client/dhclient.conf.5 client/dhclient.leases.5 \
@ -394,7 +397,8 @@ CFLAGS="%{optflags} -fno-strict-aliasing" \
--enable-systemtap \
--with-tapset-install-dir=%{tapsetdir} \
%endif
--enable-paranoia --enable-early-chroot
--enable-paranoia --enable-early-chroot \
--with-systemd
%{__make} %{?_smp_mflags}
pushd doc
%{__make} devel
@ -509,11 +513,15 @@ exit 0
# Initial installation
%systemd_post dhcpd.service dhcpd6.service dhcrelay.service
# Update
if [ $1 -gt 1 ] ; then
chown -R dhcpd:dhcpd %{_localstatedir}/lib/dhcpd/
fi
chown -R dhcpd:dhcpd %{_localstatedir}/lib/dhcpd/
for servicename in dhcpd dhcpd6 dhcrelay; do
etcservicefile=%{_sysconfdir}/systemd/system/${servicename}.service
if [ -f ${etcservicefile} ]; then
grep -q Type= ${etcservicefile} || sed -i '/\[Service\]/a Type=notify' ${etcservicefile}
fi
done
exit 0
%preun
# Package removal, not upgrade
@ -619,6 +627,9 @@ done
%doc doc/html/
%changelog
* Tue Mar 18 2014 Jiri Popelka <jpopelka@redhat.com> - 12:4.3.0-9
- support for sending startup notifications to systemd (#1077666)
* Fri Mar 07 2014 Jiri Popelka <jpopelka@redhat.com> - 12:4.3.0-8
- rename doc subpackage do devel-doc

View File

@ -5,6 +5,7 @@ After=network.target
After=time-sync.target
[Service]
Type=notify
ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
[Install]

View File

@ -5,6 +5,7 @@ After=network.target
After=time-sync.target
[Service]
Type=notify
ExecStart=/usr/sbin/dhcpd -f -6 -cf /etc/dhcp/dhcpd6.conf -user dhcpd -group dhcpd --no-pid
[Install]

View File

@ -4,6 +4,7 @@ Documentation=man:dhcrelay(8)
After=network.target
[Service]
Type=notify
ExecStart=/usr/sbin/dhcrelay -d --no-pid
[Install]