From cb63247721c928465eb6db57ace23a675126b852 Mon Sep 17 00:00:00 2001 From: SATOH Fumiyasu Date: Thu, 3 Aug 2017 00:38:14 +0900 Subject: [PATCH 1/2] Add systemd service notification support --- build/top.mk | 3 ++- configure.in | 33 +++++++++++++++++++++++++++++++++ include/portable.hin | 6 ++++++ servers/slapd/daemon.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/build/top.mk b/build/top.mk index a0ae239679..f16e75a6a3 100644 --- a/build/top.mk +++ b/build/top.mk @@ -192,6 +192,7 @@ TLS_LIBS = @TLS_LIBS@ AUTH_LIBS = @AUTH_LIBS@ SECURITY_LIBS = $(SASL_LIBS) $(KRB_LIBS) $(TLS_LIBS) $(AUTH_LIBS) ICU_LIBS = @ICU_LIBS@ +SYSTEMD_LIBS = @SYSTEMD_LIBS@ MODULES_CPPFLAGS = @SLAPD_MODULES_CPPFLAGS@ MODULES_LDFLAGS = @SLAPD_MODULES_LDFLAGS@ @@ -202,7 +203,7 @@ SLAPD_SQL_LDFLAGS = @SLAPD_SQL_LDFLAGS@ SLAPD_SQL_INCLUDES = @SLAPD_SQL_INCLUDES@ SLAPD_SQL_LIBS = @SLAPD_SQL_LIBS@ -SLAPD_LIBS = @SLAPD_LIBS@ @SLAPD_PERL_LDFLAGS@ @SLAPD_SQL_LDFLAGS@ @SLAPD_SQL_LIBS@ @SLAPD_SLP_LIBS@ @SLAPD_GMP_LIBS@ $(ICU_LIBS) +SLAPD_LIBS = @SLAPD_LIBS@ @SLAPD_PERL_LDFLAGS@ @SLAPD_SQL_LDFLAGS@ @SLAPD_SQL_LIBS@ @SLAPD_SLP_LIBS@ @SLAPD_GMP_LIBS@ $(ICU_LIBS) $(SYSTEMD_LIBS) # Our Defaults CC = $(AC_CC) diff --git a/configure.in b/configure.in index 5bb2c11910..7c972bb9c8 100644 --- a/configure.in +++ b/configure.in @@ -242,6 +242,8 @@ dnl ---------------------------------------------------------------- dnl General "with" options OL_ARG_WITH(cyrus_sasl,[ --with-cyrus-sasl with Cyrus SASL support], auto, [auto yes no] ) +OL_ARG_WITH(systemd,[ --with-systemd with systemd service notification support], + auto, [auto yes no] ) OL_ARG_WITH(fetch,[ --with-fetch with fetch(3) URL support], auto, [auto yes no] ) OL_ARG_WITH(threads,[ --with-threads with threads], @@ -615,6 +617,7 @@ SLAPI_LIBS= LIBSLAPI= AUTH_LIBS= ICU_LIBS= +SYSTEMD_LIBS= SLAPD_SLP_LIBS= SLAPD_GMP_LIBS= @@ -2192,6 +2195,34 @@ else fi fi +dnl ---------------------------------------------------------------- +dnl +dnl Check for systemd +dnl +WITH_SYSTEMD=no +ol_link_systemd=no +if test $ol_with_systemd != no ; then + AC_CHECK_HEADERS(systemd/sd-daemon.h) + + if test $ac_cv_header_systemd_sd_daemon_h = yes; then + AC_CHECK_LIB(systemd, sd_notify, + [ol_link_systemd="-lsystemd"]) + fi + + if test $ol_link_systemd = no ; then + if test $ol_with_systemd != auto ; then + AC_MSG_ERROR([Could not locate systemd]) + else + AC_MSG_WARN([Could not locate systemd]) + AC_MSG_WARN([systemd service notification not supported!]) + fi + else + AC_DEFINE(HAVE_SYSTEMD,1,[define if you have systemd]) + SYSTEMD_LIBS="$ol_link_systemd" + WITH_SYSTEMD=yes + fi +fi + dnl ---------------------------------------------------------------- dnl Check for entropy sources if test $cross_compiling != yes && test "$ac_cv_mingw32" != yes ; then @@ -3167,6 +3198,7 @@ AC_SUBST(WITH_SASL) AC_SUBST(WITH_TLS) AC_SUBST(WITH_MODULES_ENABLED) AC_SUBST(WITH_ACI_ENABLED) +AC_SUBST(WITH_SYSTEMD) AC_SUBST(BUILD_THREAD) AC_SUBST(BUILD_LIBS_DYNAMIC) @@ -3248,6 +3280,7 @@ AC_SUBST(SLAPI_LIBS) AC_SUBST(LIBSLAPI) AC_SUBST(AUTH_LIBS) AC_SUBST(ICU_LIBS) +AC_SUBST(SYSTEMD_LIBS) AC_SUBST(SLAPD_SLP_LIBS) AC_SUBST(SLAPD_GMP_LIBS) diff --git a/include/portable.hin b/include/portable.hin index 9e0f83edfb..add42d831b 100644 --- a/include/portable.hin +++ b/include/portable.hin @@ -649,6 +649,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYSLOG_H +/* define if you have systemd */ +#undef HAVE_SYSTEMD + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYSTEMD_SD_DAEMON_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_DEVPOLL_H diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 6947df5f9a..c7e758f006 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -41,6 +41,10 @@ #include "ldap_rq.h" +#ifdef HAVE_SYSTEMD_SD_DAEMON_H +#include +#endif + #ifdef HAVE_POLL #include #endif @@ -88,6 +92,9 @@ int slapd_tcp_rmem; int slapd_tcp_wmem; #endif /* LDAP_TCP_BUFFER */ +static ldap_pvt_thread_mutex_t listener_init_mutex; +static ldap_pvt_thread_cond_t listener_init_cond; + Listener **slap_listeners = NULL; static volatile sig_atomic_t listening = 1; /* 0 when slap_listeners closed */ static ldap_pvt_thread_t *listener_tid; @@ -2303,6 +2310,8 @@ slapd_daemon_task( "daemon: listen(%s, 5) failed errno=%d (%s)\n", slap_listeners[l]->sl_url.bv_val, err, sock_errstr(err) ); + slapd_shutdown = 2; + ldap_pvt_thread_cond_signal( &listener_init_cond ); return (void*)-1; } @@ -2312,12 +2321,15 @@ slapd_daemon_task( "set nonblocking on a listening socket failed\n", 0, 0, 0 ); slapd_shutdown = 2; + ldap_pvt_thread_cond_signal( &listener_init_cond ); return (void*)-1; } slapd_add( slap_listeners[l]->sl_sd, 0, slap_listeners[l], -1 ); } + ldap_pvt_thread_cond_signal( &listener_init_cond ); + #ifdef HAVE_NT_SERVICE_MANAGER if ( started_event != NULL ) { ldap_pvt_thread_cond_signal( &started_event ); @@ -2892,6 +2904,9 @@ slapd_daemon( void ) SLAP_SOCK_INIT(i); } + ldap_pvt_thread_mutex_init( &listener_init_mutex ); + ldap_pvt_thread_cond_init( &listener_init_cond ); + for ( i=0; i Date: Fri, 11 Aug 2017 19:33:32 +0900 Subject: [PATCH 2/2] Add slapd.service for systemd --- build/top.mk | 1 + configure.in | 24 +++++++++++++++++++----- servers/slapd/Makefile.in | 14 ++++++++++++-- servers/slapd/slapd.service | 11 +++++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 servers/slapd/slapd.service diff --git a/build/top.mk b/build/top.mk index f16e75a6a3..062dae57cf 100644 --- a/build/top.mk +++ b/build/top.mk @@ -45,6 +45,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ sysconfdir = @sysconfdir@$(ldap_subdir) schemadir = $(sysconfdir)/schema +systemdsystemunitdir = @systemdsystemunitdir@ PLAT = @PLAT@ EXEEXT = @EXEEXT@ diff --git a/configure.in b/configure.in index 7c972bb9c8..9a461cb3c2 100644 --- a/configure.in +++ b/configure.in @@ -693,6 +693,7 @@ fi AC_LIBTOOL_WIN32_DLL AC_LIBTOOL_DLOPEN AC_PROG_LIBTOOL +AC_PATH_PROG(PKG_CONFIG, pkg-config, no) dnl ---------------------------------------------------------------- dnl Perl @@ -2107,12 +2108,13 @@ dnl ---------------------------------------------------------------- dnl WiredTiger ol_link_wt=no if test $ol_enable_wt != no ; then - AC_CHECK_PROG(PKGCONFIG,pkg-config,yes) - if test "$PKGCONFIG" != yes ; then - AC_MSG_ERROR([could not locate pkg-config]) + if test "$PKG_CONFIG" != no; then + WT_INCS=`$PKG_CONFIG --cflags wiredtiger` + WT_LIBS=`$PKG_CONFIG --libs wiredtiger` + else + WT_INCS= + WT_LIBS="-lwiredtiger" fi - WT_INCS=`pkg-config --cflags wiredtiger` - WT_LIBS=`pkg-config --libs wiredtiger` save_CFLAGS="$CFLAGS" save_LDFLAGS="$LDFLAGS" @@ -2200,6 +2202,7 @@ dnl dnl Check for systemd dnl WITH_SYSTEMD=no +systemdsystemunitdir= ol_link_systemd=no if test $ol_with_systemd != no ; then AC_CHECK_HEADERS(systemd/sd-daemon.h) @@ -2223,6 +2226,17 @@ if test $ol_with_systemd != no ; then fi fi +if test $WITH_SYSTEMD = yes; then + if test "$PKG_CONFIG" != no ; then + systemdsystemunitdir=`$PKG_CONFIG --variable=systemdsystemunitdir systemd` + elif test -d /usr/lib/systemd/system; then + systemdsystemunitdir=/usr/lib/systemd/system + else + systemdsystemunitdir=/lib/systemd/system + fi +fi +AC_SUBST(systemdsystemunitdir) + dnl ---------------------------------------------------------------- dnl Check for entropy sources if test $cross_compiling != yes && test "$ac_cv_mingw32" != yes ; then diff --git a/servers/slapd/Makefile.in b/servers/slapd/Makefile.in index 03275372fc..1118dbde73 100644 --- a/servers/slapd/Makefile.in +++ b/servers/slapd/Makefile.in @@ -404,11 +404,15 @@ all-cffiles: slapd $(SLAPD_DYNAMIC_BACKENDS) dynamic_overlays $(SED) -e "s;%SYSCONFDIR%;$$sysconfdir;" \ -e "s;%LOCALSTATEDIR%;$$localstatedir;" \ -e "s;%MODULEDIR%;$$moduledir;" \ - $(srcdir)/slapd.conf > slapd.conf.tmp ; \ + $(srcdir)/slapd.conf > slapd.conf.tmp || exit $$?; \ $(SED) -e "s;%SYSCONFDIR%;$$sysconfdir;" \ -e "s;%LOCALSTATEDIR%;$$localstatedir;" \ -e "s;%MODULEDIR%;$$moduledir;" \ - $(srcdir)/slapd.ldif > slapd.ldif.tmp ; \ + $(srcdir)/slapd.ldif > slapd.ldif.tmp || exit $$? + @if test -n "$(systemdsystemunitdir)"; then \ + $(SED) -e "s;%LIBEXECDIR%;$(libexecdir);" \ + $(srcdir)/slapd.service > slapd.service.tmp ; \ + fi touch all-cffiles install-schema: FORCE @@ -442,6 +446,12 @@ install-conf: FORCE else \ echo "PRESERVING EXISTING CONFIGURATION FILE $(DESTDIR)$(sysconfdir)/slapd.ldif" ; \ fi + if test -n "$(systemdsystemunitdir)" && test ! -f $(DESTDIR)$(systemdsystemunitdir)/slapd.service; then \ + $(MKDIR) $(DESTDIR)$(systemdsystemunitdir); \ + echo "installing slapd.service in $(systemdsystemunitdir)"; \ + echo "$(INSTALL) $(INSTALLFLAGS) -m 644 slapd.service.tmp $(DESTDIR)$(systemdsystemunitdir)/slapd.service"; \ + $(INSTALL) $(INSTALLFLAGS) -m 644 slapd.service.tmp $(DESTDIR)$(systemdsystemunitdir)/slapd.service; \ + fi install-db-config: FORCE @-$(MKDIR) $(DESTDIR)$(localstatedir) $(DESTDIR)$(sysconfdir) diff --git a/servers/slapd/slapd.service b/servers/slapd/slapd.service new file mode 100644 index 0000000000..da03200e81 --- /dev/null +++ b/servers/slapd/slapd.service @@ -0,0 +1,11 @@ +[Unit] +Description=OpenLDAP Server +After=syslog.target network-online.target +Documentation=man:slapd + +[Service] +Type=notify +ExecStart=%LIBEXECDIR%/slapd -d 0 -h "ldapi:/// ldap:///" + +[Install] +WantedBy=multi-user.target