2a8b17c
#! /bin/bash
2a8b17c
2a8b17c
BDII_CONF=${BDII_CONF:-/etc/bdii/bdii.conf}
2a8b17c
2a8b17c
[ -r "${BDII_CONF}" ] && . "${BDII_CONF}"
2a8b17c
2a8b17c
BDII_USER=${BDII_USER:-ldap}
2a8b17c
BDII_VAR_DIR=${BDII_VAR_DIR:-/var/lib/bdii}
2a8b17c
SLAPD=${SLAPD:-/usr/sbin/slapd}
2a8b17c
SLAPD_CONF=${SLAPD_CONF:-/etc/bdii/bdii-slapd.conf}
2a8b17c
SLAPD_HOST=${SLAPD_HOST:-0.0.0.0}
2a8b17c
SLAPD_PORT=${SLAPD_PORT:-2170}
2a8b17c
BDII_IPV6_SUPPORT=${BDII_IPV6_SUPPORT:-no}
2a8b17c
SLAPD_HOST6=${SLAPD_HOST6:-::}
2a8b17c
SLAPD_DB_DIR=${SLAPD_DB_DIR:-$BDII_VAR_DIR/db}
2a8b17c
DB_CONFIG=${DB_CONFIG:-/etc/bdii/DB_CONFIG}
2a8b17c
DELAYED_DELETE=${DELAYED_DELETE:-${BDII_VAR_DIR}/delayed_delete.pkl}
2a8b17c
BDII_RAM_SIZE=${BDII_RAM_SIZE:-1500M}
2a8b17c
2a8b17c
if [ "${BDII_IPV6_SUPPORT}" == "yes" ]; then
2a8b17c
    SLAPD_HOST_STRING="'ldap://${SLAPD_HOST}:${SLAPD_PORT} ldap://[${SLAPD_HOST6}]:${SLAPD_PORT}'"
2a8b17c
else
2a8b17c
    SLAPD_HOST_STRING="ldap://${SLAPD_HOST}:${SLAPD_PORT}"
2a8b17c
fi
2a8b17c
2a8b17c
if [ -x /sbin/runuser ] ; then
2a8b17c
    RUNUSER=/sbin/runuser
2a8b17c
else
2a8b17c
    RUNUSER=su
2a8b17c
fi
2a8b17c
2a8b17c
# Create RAM Disk
2a8b17c
if [ "${BDII_RAM_DISK}" = "yes" ]; then
2a8b17c
    mkdir -p ${SLAPD_DB_DIR}
2a8b17c
    mount -t tmpfs -o size=${BDII_RAM_SIZE},mode=0744 tmpfs ${SLAPD_DB_DIR}
2a8b17c
fi
2a8b17c
2a8b17c
# Remove delayed_delete.pkl if it exists
2a8b17c
if [ -f "${DELAYED_DELETE}" ] ; then
2a8b17c
    rm -f ${DELAYED_DELETE}
2a8b17c
fi
2a8b17c
2a8b17c
#Initialize the database directory.
2a8b17c
mkdir -p ${SLAPD_DB_DIR}/stats
2a8b17c
mkdir -p ${SLAPD_DB_DIR}/glue
2a8b17c
mkdir -p ${SLAPD_DB_DIR}/grid
2a8b17c
mkdir -p ${BDII_VAR_DIR}/archive
2a8b17c
2a8b17c
chown -R ${BDII_USER}:${BDII_USER} ${BDII_VAR_DIR}
2a8b17c
chown -R ${BDII_USER}:${BDII_USER} ${SLAPD_DB_DIR}
2a8b17c
[ -x /sbin/restorecon ] && /sbin/restorecon -R ${BDII_VAR_DIR}
2a8b17c
2a8b17c
mkdir -p /var/run/bdii/db
2a8b17c
chown -R ${BDII_USER}:${BDII_USER} /var/run/bdii
2a8b17c
[ -x /sbin/restorecon ] && /sbin/restorecon -R /var/run/bdii/db
2a8b17c
2a8b17c
$RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${SLAPD_DB_DIR}/stats/* 2>/dev/null"
2a8b17c
$RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${SLAPD_DB_DIR}/glue/* 2>/dev/null"
2a8b17c
$RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${SLAPD_DB_DIR}/grid/* 2>/dev/null"
2a8b17c
$RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${BDII_VAR_DIR}/old.ldif 2>/dev/null"
2a8b17c
$RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG} ${SLAPD_DB_DIR}/grid/"
2a8b17c
$RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG} ${SLAPD_DB_DIR}/stats/"
2a8b17c
$RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG} ${SLAPD_DB_DIR}/glue/"
2a8b17c
2a8b17c
if [ ${SLAPD_CONF} = "/etc/bdii/bdii-top-slapd.conf" ] ; then
2a8b17c
    $RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG}_top ${SLAPD_DB_DIR}/grid/DB_CONFIG"
2a8b17c
    $RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG}_top ${SLAPD_DB_DIR}/stats/DB_CONFIG"
2a8b17c
    $RUNUSER -s /bin/sh ${BDII_USER} -c "ln -sf ${DB_CONFIG}_top ${SLAPD_DB_DIR}/glue/DB_CONFIG"
2a8b17c
    $RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${BDII_VAR_DIR}/gip/cache/gip/top-urls.conf/* 2>/dev/null"
2a8b17c
    $RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${BDII_VAR_DIR}/gip/cache/gip/top-urls.conf-glue2/* 2>/dev/null"
2a8b17c
else
2a8b17c
    if [ -r "${BDII_VAR_DIR}/gip/cache" ]; then
2a8b17c
        $RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${BDII_VAR_DIR}/gip/cache/gip/site-urls.conf/* 2>/dev/null"
2a8b17c
        $RUNUSER -s /bin/sh ${BDII_USER} -c "rm -f ${BDII_VAR_DIR}/gip/cache/gip/site-urls.conf-glue2/* 2>/dev/null"
2a8b17c
    fi
2a8b17c
fi
2a8b17c
2a8b17c
COMMAND="${SLAPD} -f ${SLAPD_CONF} -h ${SLAPD_HOST_STRING} -u ${BDII_USER}"
2a8b17c
exec ${COMMAND}