diff --git a/bdii-slapd-start b/bdii-slapd-start new file mode 100755 index 0000000..d01c7fe --- /dev/null +++ b/bdii-slapd-start @@ -0,0 +1,79 @@ +#! /bin/bash + +BDII_CONF=${BDII_CONF:-/etc/bdii/bdii.conf} + +[ -r "${BDII_CONF}" ] && . "${BDII_CONF}" + +BDII_USER=${BDII_USER:-ldap} +BDII_VAR_DIR=${BDII_VAR_DIR:-/var/lib/bdii} +SLAPD=${SLAPD:-/usr/sbin/slapd} +SLAPD_CONF=${SLAPD_CONF:-/etc/bdii/bdii-slapd.conf} +SLAPD_HOST=${SLAPD_HOST:-0.0.0.0} +SLAPD_PORT=${SLAPD_PORT:-2170} +BDII_IPV6_SUPPORT=${BDII_IPV6_SUPPORT:-no} +SLAPD_HOST6=${SLAPD_HOST6:-::} +SLAPD_DB_DIR=${SLAPD_DB_DIR:-$BDII_VAR_DIR/db} +DB_CONFIG=${DB_CONFIG:-/etc/bdii/DB_CONFIG} +DELAYED_DELETE=${DELAYED_DELETE:-${BDII_VAR_DIR}/delayed_delete.pkl} +BDII_RAM_SIZE=${BDII_RAM_SIZE:-1500M} + +if [ "${BDII_IPV6_SUPPORT}" == "yes" ]; then + SLAPD_HOST_STRING="'ldap://${SLAPD_HOST}:${SLAPD_PORT} ldap://[${SLAPD_HOST6}]:${SLAPD_PORT}'" +else + SLAPD_HOST_STRING="ldap://${SLAPD_HOST}:${SLAPD_PORT}" +fi + +if [ -x /sbin/runuser ] ; then + RUNUSER=/sbin/runuser +else + RUNUSER=su +fi + +# Create RAM Disk +if [ "${BDII_RAM_DISK}" = "yes" ]; then + mkdir -p ${SLAPD_DB_DIR} + mount -t tmpfs -o size=${BDII_RAM_SIZE},mode=0744 tmpfs ${SLAPD_DB_DIR} +fi + +# Remove delayed_delete.pkl if it exists +if [ -f "${DELAYED_DELETE}" ] ; then + rm -f ${DELAYED_DELETE} +fi + +#Initialize the database directory. +mkdir -p ${SLAPD_DB_DIR}/stats +mkdir -p ${SLAPD_DB_DIR}/glue +mkdir -p ${SLAPD_DB_DIR}/grid +mkdir -p ${BDII_VAR_DIR}/archive + +chown -R ${BDII_USER}:${BDII_USER} ${BDII_VAR_DIR} +chown -R ${BDII_USER}:${BDII_USER} ${SLAPD_DB_DIR} +[ -x /sbin/restorecon ] && /sbin/restorecon -R ${BDII_VAR_DIR} + +mkdir -p /var/run/bdii/db +chown -R ${BDII_USER}:${BDII_USER} /var/run/bdii +[ -x /sbin/restorecon ] && /sbin/restorecon -R /var/run/bdii/db + +$RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${SLAPD_DB_DIR}/stats/* 2>/dev/null" +$RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${SLAPD_DB_DIR}/glue/* 2>/dev/null" +$RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${SLAPD_DB_DIR}/grid/* 2>/dev/null" +$RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${BDII_VAR_DIR}/old.ldif 2>/dev/null" +$RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG} ${SLAPD_DB_DIR}/grid/" +$RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG} ${SLAPD_DB_DIR}/stats/" +$RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG} ${SLAPD_DB_DIR}/glue/" + +if [ ${SLAPD_CONF} = "/etc/bdii/bdii-top-slapd.conf" ] ; then + $RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG}_top ${SLAPD_DB_DIR}/grid/DB_CONFIG" + $RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG}_top ${SLAPD_DB_DIR}/stats/DB_CONFIG" + $RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG}_top ${SLAPD_DB_DIR}/glue/DB_CONFIG" + $RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${BDII_VAR_DIR}/gip/cache/gip/top-urls.conf/* 2>/dev/null" + $RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${BDII_VAR_DIR}/gip/cache/gip/top-urls.conf-glue2/* 2>/dev/null" +else + if [ -r "${BDII_VAR_DIR}/gip/cache" ]; then + $RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${BDII_VAR_DIR}/gip/cache/gip/site-urls.conf/* 2>/dev/null" + $RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${BDII_VAR_DIR}/gip/cache/gip/site-urls.conf-glue2/* 2>/dev/null" + fi +fi + +COMMAND="${SLAPD} -f ${SLAPD_CONF} -h ${SLAPD_HOST_STRING} -u ${BDII_USER}" +exec ${COMMAND} diff --git a/bdii-slapd.service b/bdii-slapd.service new file mode 100644 index 0000000..c6ff536 --- /dev/null +++ b/bdii-slapd.service @@ -0,0 +1,11 @@ +[Unit] +Description=Berkeley Database Information Index - slapd +After=remote_fs.target syslog.target +BindTo=bdii.service + +[Service] +Type=forking +EnvironmentFile=-/etc/sysconfig/bdii +PIDFile=/var/run/bdii/db/slapd.pid +ExecStart=/usr/share/bdii/bdii-slapd-start +ExecStopPost=/bin/sh -c "mountpoint -q /var/lib/bdii/db && umount /var/lib/bdii/db || :" diff --git a/bdii.service b/bdii.service new file mode 100644 index 0000000..4eb3022 --- /dev/null +++ b/bdii.service @@ -0,0 +1,21 @@ +[Unit] +Description=Berkeley Database Information Index +Documentation=man:bdii-update(1) +After=bdii-slapd.service +Requires=bdii-slapd.service + +[Service] +Type=forking +PIDFile=/var/run/bdii/bdii-update.pid +EnvironmentFile=-/etc/sysconfig/bdii +ExecStart=/bin/sh -c ' \ + BDII_CONF=$${BDII_CONF:-/etc/bdii/bdii.conf} ; \ + [ -r "$${BDII_CONF}" ] && . "$${BDII_CONF}" ; \ + BDII_USER=$${BDII_USER:-ldap} ; \ + BDII_UPDATE=$${BDII_UPDATE:-/usr/sbin/bdii-update} ; \ + export SLAPD_CONF=$${SLAPD_CONF:-/etc/bdii/bdii-slapd.conf} ; \ + /sbin/runuser -s /bin/sh $${BDII_USER} -c "$${BDII_UPDATE} -c $${BDII_CONF} -d ; sleep 2" \ +' + +[Install] +WantedBy=multi-user.target diff --git a/bdii.spec b/bdii.spec index 9744698..1c0c6d2 100644 --- a/bdii.spec +++ b/bdii.spec @@ -1,6 +1,12 @@ +%if %{?fedora}%{!?fedora:0} >= 25 || %{?rhel}%{!?rhel:0} >= 8 +%global use_systemd 1 +%else +%global use_systemd 0 +%endif + Name: bdii Version: 5.2.23 -Release: 4%{?dist} +Release: 5%{?dist} Summary: The Berkeley Database Information Index (BDII) Group: System Environment/Daemons @@ -11,8 +17,14 @@ URL: http://gridinfo.web.cern.ch/ # svn export http://svn.cern.ch/guest/gridinfo/bdii/tags/R_5_2_23 %{name}-%{version} # tar -z -c -f %{name}-%{version}.tar.gz %{name}-%{version} Source: %{name}-%{version}.tar.gz +Source1: %{name}.service +Source2: %{name}-slapd.service +Source3: %{name}-slapd-start BuildArch: noarch BuildRoot: %{_tmppath}/%{name}-%{version}-build +%if %{use_systemd} +BuildRequires: systemd-units +%endif Requires: openldap-clients Requires: openldap-servers @@ -22,11 +34,17 @@ Requires: openldap-servers-overlays %endif Requires: glue-schema >= 2.0.10 -Requires(post): chkconfig Requires(post): expect +%if %{use_systemd} +Requires(post): systemd-units +Requires(preun): systemd-units +Requires(postun): systemd-units +%else +Requires(post): chkconfig Requires(preun): chkconfig Requires(preun): initscripts Requires(postun): initscripts +%endif %if %{?fedora}%{!?fedora:0} >= 23 || %{?rhel}%{!?rhel:0} >= 8 Requires(post): policycoreutils-python-utils @@ -70,29 +88,33 @@ sed -e '/moduleload back_relay/d' \ -i %{buildroot}%{_sysconfdir}/%{name}/*-slapd.conf %endif +%if %{use_systemd} +rm %{buildroot}%{_initrddir}/%{name} +mkdir -p %{buildroot}%{_unitdir} +install -m 644 -p %SOURCE1 %SOURCE2 %{buildroot}%{_unitdir} +mkdir -p %{buildroot}%{_datadir}/%{name} +install -p %SOURCE3 %{buildroot}%{_datadir}/%{name} +%endif + %clean rm -rf %{buildroot} +%if %{use_systemd} %pre -# Temp fix for upgrade from 5.2.5 to 5.2.7 -service %{name} status > /dev/null 2>&1 -if [ $? -eq 0 ]; then - touch %{_localstatedir}/run/%{name}/bdii.upgrade - service %{name} stop > /dev/null 2>&1 -fi +# Remove old init config when systemd is used +/sbin/chkconfig --del %{name} >/dev/null 2>&1 || : +%endif %post sed "s/\(rootpw *\)secret/\1$(mkpasswd -s 0 | tr '/' 'x')/" \ -i %{_sysconfdir}/%{name}/bdii-slapd.conf \ %{_sysconfdir}/%{name}/bdii-top-slapd.conf -# Temp fix for upgrade from 5.2.5 to 5.2.7 -if [ -f %{_localstatedir}/run/%{name}/bdii.upgrade ]; then - rm -f %{_localstatedir}/run/%{name}/bdii.upgrade - service %{name} start > /dev/null 2>&1 -fi - +%if %{use_systemd} +%systemd_post %{name}.service +%else /sbin/chkconfig --add %{name} +%endif %if %{?fedora}%{!?fedora:0} >= 5 || %{?rhel}%{!?rhel:0} >= 5 semanage port -a -t ldap_port_t -p tcp 2170 2>/dev/null || : @@ -103,15 +125,24 @@ semanage fcontext -d -t slapd_db_t "%{_localstatedir}/run/%{name}(/.*)?" 2>/dev/ %endif %preun +%if %{use_systemd} +%systemd_preun %{name}.service +%else if [ $1 -eq 0 ]; then service %{name} stop > /dev/null 2>&1 /sbin/chkconfig --del %{name} fi +%endif %postun +%if %{use_systemd} +%systemd_postun_with_restart %{name}.service +%else if [ $1 -ge 1 ]; then service %{name} condrestart > /dev/null 2>&1 fi +%endif + %if %{?fedora}%{!?fedora:0} >= 5 || %{?rhel}%{!?rhel:0} >= 5 if [ $1 -eq 0 ]; then semanage port -d -t ldap_port_t -p tcp 2170 2>/dev/null || : @@ -132,12 +163,22 @@ fi %attr(-,ldap,ldap) %config %{_sysconfdir}/%{name}/bdii-top-slapd.conf %config(noreplace) %{_sysconfdir}/sysconfig/%{name} %config(noreplace) %{_sysconfdir}/logrotate.d/%{name} +%if %{use_systemd} +%{_unitdir}/bdii.service +%{_unitdir}/bdii-slapd.service +%dir %{_datadir}/%{name} +%{_datadir}/%{name}/bdii-slapd-start +%else %{_initrddir}/%{name} +%endif %{_sbindir}/bdii-update %{_mandir}/man1/bdii-update.1* %doc copyright %changelog +* Mon Aug 15 2016 Mattias Ellert - 5.2.23-5 +- Convert to systemd unit files (Fedora 25+) + * Wed Feb 03 2016 Fedora Release Engineering - 5.2.23-4 - Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild