2017-05-25 13:29:15 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
NAME="OPENLDAP"
|
2023-05-19 05:30:02 +00:00
|
|
|
SLAPD_CONFIG=${SLAPD_CONFIG:-"/etc/openldap/slapd.d/cn=config"}
|
2017-05-25 13:29:15 +00:00
|
|
|
|
|
|
|
function stop {
|
|
|
|
echo "Stopping ${NAME}"
|
2023-05-19 10:52:43 +00:00
|
|
|
kill $(pidof slapd)
|
2017-05-25 13:29:15 +00:00
|
|
|
}
|
|
|
|
|
2023-05-19 05:30:02 +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
|
|
|
|
|
2023-05-19 05:30:02 +00:00
|
|
|
if [ -z "$@" ]; then
|
2017-05-25 13:29:15 +00:00
|
|
|
SLAPD_URLS="ldapi:/// ldap:/// ldaps:///"
|
|
|
|
SLAPD_OPTIONS="-d 256"
|
|
|
|
|
2023-05-19 05:30:02 +00:00
|
|
|
# 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
|