kdc: add sd_notify start/stop signals
This commit adds optional integration with systemd's state notifification system. When built with libsystemd, the KDC notifies systemd once it is ready to serve and when it begins a clean shutdown, as well as publishing a status line reporting how many worker processes are running.
This commit is contained in:
@@ -196,6 +196,22 @@ AM_CONDITIONAL([HAVE_CAPNG], [test "$with_capng" != "no"])
|
||||
AC_SUBST([CAPNG_CFLAGS])
|
||||
AC_SUBST([CAPNG_LIBS])
|
||||
|
||||
dnl libsystemd
|
||||
AC_ARG_WITH([systemd],
|
||||
AC_HELP_STRING([--with-systemd], [use libsystemd for sd_notify service notifications @<:@default=check@:>@]),
|
||||
[],
|
||||
[with_systemd=check])
|
||||
if test "$with_systemd" != "no"; then
|
||||
PKG_CHECK_MODULES([SYSTEMD], [libsystemd],
|
||||
[with_systemd=yes],[with_systemd=no])
|
||||
fi
|
||||
if test "$with_systemd" = "yes"; then
|
||||
AC_DEFINE_UNQUOTED([HAVE_SYSTEMD], 1, [whether libsystemd is available for sd_notify])
|
||||
fi
|
||||
AM_CONDITIONAL([HAVE_SYSTEMD], [test "$with_systemd" != "no"])
|
||||
AC_SUBST([SYSTEMD_CFLAGS])
|
||||
AC_SUBST([SYSTEMD_LIBS])
|
||||
|
||||
dnl mitdb
|
||||
AC_ARG_WITH([mitdb],
|
||||
AC_HELP_STRING([--with-mitdb], [Path to MIT Kerberos DB include header and shared object]),
|
||||
|
||||
+2
-2
@@ -198,12 +198,12 @@ LDADD = $(top_builddir)/lib/hdb/libhdb.la \
|
||||
$(LIB_roken) \
|
||||
$(DB3LIB) $(DB1LIB) $(LMDBLIB) $(NDBMLIB)
|
||||
|
||||
kdc_LDADD = libkdc.la $(LDADD) $(LIB_pidfile) $(CAPNG_LIBS)
|
||||
kdc_LDADD = libkdc.la $(LDADD) $(LIB_pidfile) $(CAPNG_LIBS) $(SYSTEMD_LIBS)
|
||||
|
||||
if FRAMEWORK_SECURITY
|
||||
kdc_LDFLAGS = -framework SystemConfiguration -framework CoreFoundation
|
||||
endif
|
||||
kdc_CFLAGS = $(CAPNG_CFLAGS)
|
||||
kdc_CFLAGS = $(CAPNG_CFLAGS) $(SYSTEMD_CFLAGS)
|
||||
|
||||
kdc_replay_LDADD = libkdc.la $(LDADD) $(LIB_pidfile)
|
||||
kdc_tester_LDADD = libkdc.la $(LDADD) $(LIB_pidfile) $(LIB_heimbase)
|
||||
|
||||
@@ -33,6 +33,10 @@
|
||||
|
||||
#include "kdc_locl.h"
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
#include <systemd/sd-daemon.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* a tuple describing on what to listen
|
||||
*/
|
||||
@@ -1209,6 +1213,11 @@ start_kdc(krb5_context context,
|
||||
|
||||
roken_detach_finish(NULL, daemon_child);
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
sd_notify(0, "READY=1");
|
||||
sd_notify(0, "STATUS=Serving requests");
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FORK
|
||||
if (!testing_flag) {
|
||||
/* Note that we might never execute the body of this loop */
|
||||
@@ -1250,12 +1259,20 @@ start_kdc(krb5_context context,
|
||||
kdc_log(context, config, 3, "KDC worker process started: %d",
|
||||
pid);
|
||||
num_kdcs++;
|
||||
#ifdef HAVE_SYSTEMD
|
||||
sd_notifyf(0, "STATUS=Serving requests; %d of %d KDC worker "
|
||||
"process(es) running", num_kdcs, max_kdcs);
|
||||
#endif
|
||||
/* Slow down the creation of KDCs... */
|
||||
select_sleep(12500);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
sd_notify(0, "STOPPING=1");
|
||||
#endif
|
||||
|
||||
/* Closing these sockets should cause the kids to die... */
|
||||
|
||||
close(islive[0]);
|
||||
@@ -1307,11 +1324,17 @@ start_kdc(krb5_context context,
|
||||
kdc_log(context, config, 3, "KDC master process exiting");
|
||||
} else {
|
||||
loop(context, config, &d, &ndescr, -1);
|
||||
#ifdef HAVE_SYSTEMD
|
||||
sd_notify(0, "STOPPING=1");
|
||||
#endif
|
||||
kdc_log(context, config, 3, "KDC exiting");
|
||||
}
|
||||
free(pids);
|
||||
#else
|
||||
loop(context, config, &d, &ndescr, -1);
|
||||
#ifdef HAVE_SYSTEMD
|
||||
sd_notify(0, "STOPPING=1");
|
||||
#endif
|
||||
kdc_log(context, config, 3, "KDC exiting");
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user