ldap/init

43 lines
902 B
Plaintext
Raw Normal View History

2017-05-25 13:29:15 +00:00
#!/bin/bash
set -e
NAME="OPENLDAP"
SLAPD_CONFIG=${SLAPD_CONFIG:-"/etc/openldap/slapd.d/cn=config"}
2017-05-25 13:29:15 +00:00
function stop {
echo "Stopping ${NAME}"
kill $(pidof slapd)
2017-05-25 13:29:15 +00:00
}
function mp() {
set +e
mountpoint -q $1
local mp=$?
set -e
return ${mp}
}
2017-05-25 13:29:15 +00:00
trap 'stop' SIGTERM
if [ -z "$@" ]; then
2017-05-25 13:29:15 +00:00
SLAPD_URLS="ldapi:/// ldap:/// ldaps:///"
SLAPD_OPTIONS="-d 256"
# If /etc/openldap is an external mount point
if mp ${SLAPD_CONFIG}; then
echo "* ${SLAPD_CONFIG} is mounted, checking for existing config"
if [ -f ${SLAPD_CONFIG}/olcDatabase=\{0\}config.ldif ]; then
echo "= ${SLAPD_CONFIG} existing configuration detected, aborting..."
else
echo "- ${SLAPD_CONFIG} populating default configuration"
cp -pr ${SLAPD_CONFIG}.orig/* ${SLAPD_CONFIG}
fi
fi
2017-05-25 13:29:15 +00:00
[ -x /usr/sbin/slapd ] && /usr/sbin/slapd -u ldap -h "${SLAPD_URLS}" $SLAPD_OPTIONS &
wait
else
exec $@
fi