69 lines
1.5 KiB
Bash
Executable File
69 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
NAME="OPENLDAP"
|
|
|
|
SLAPD_BASE=${SLAPD_BASE:-"/etc/openldap/slapd.d"}
|
|
SLAPD_CONFIG=${SLAPD_CONFIG:-"${SLAPD_BASE}/cn=config"}
|
|
SLAPD_INIT=${SLAPD_INIT:="/etc/openldap/slapd.ldif"}
|
|
SLAPD_DEBUG=${SLAPD_DEBUG:-0}
|
|
SLAPD_URLS=${SLAPD_URLS:-"ldapi:/// ldap:/// ldaps:///"}
|
|
SLAPD_OPTIONS="${SLAPD_OPTIONS} -d ${SLAPD_DEBUG}"
|
|
|
|
function stop {
|
|
echo "Stopping ${NAME}"
|
|
kill $(pidof slapd)
|
|
}
|
|
|
|
function mp() {
|
|
set +e
|
|
mountpoint -q $1
|
|
local mp=$?
|
|
set -e
|
|
return ${mp}
|
|
}
|
|
|
|
trap 'stop' SIGTERM
|
|
|
|
if [ -z "$@" ]; then
|
|
# If /etc/openldap is an external mount point
|
|
if [ -e ${SLAPD_CONFIG}/olcDatabase=\{0\}config.ldif ]; then
|
|
echo "* [${SLAPD_CONFIG}] exists, ready to go"
|
|
else
|
|
|
|
echo "- [${SLAPD_CONFIG}] rebuilding schema configuration"
|
|
|
|
slapadd -n 0 -F ${SLAPD_BASE} -l ${SLAPD_INIT}
|
|
|
|
# Add custom schema definitions
|
|
for f in /etc/openldap/schema/add.d/*.ldif; do
|
|
[ -e "${f}" ] || continue
|
|
|
|
echo "- Processing SCHEMA item [${f}]"
|
|
slapadd -b cn=config -l ${f}
|
|
done
|
|
|
|
for f in /etc/openldap/schema/modify.d/*.ldif; do
|
|
[ -e "${f}" ] || continue
|
|
|
|
echo "- Processing SCHEMA item [${f}]"
|
|
slapmodify -b cn=config -l ${f}
|
|
done
|
|
|
|
# Add custom data definitions
|
|
for f in /etc/openldap/data/init.d/*.ldif; do
|
|
[ -e "${f}" ] || continue
|
|
|
|
echo "- Processing DATA items [${f}]"
|
|
slapadd -b cn=config -l ${f}
|
|
done
|
|
|
|
chown -R ldap:ldap ${SLAPD_CONFIG}*
|
|
fi
|
|
|
|
[ -x /usr/sbin/slapd ] && /usr/sbin/slapd -u ldap -h "${SLAPD_URLS}" $SLAPD_OPTIONS &
|
|
wait
|
|
else
|
|
exec $@
|
|
fi
|