diff --git a/Dockerfile b/Dockerfile index 3e2c941..c5d1e34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,11 @@ RUN sed -i -e 's/dc=my-domain,dc=com/c=AU/' /etc/openldap/slapd.ldif \ && mkdir /var/lib/openldap/run \ && chown -R ldap:ldap /etc/openldap/slapd.d /var/lib/openldap/data /var/lib/openldap/run +ENV SLAPD_CONFIG /etc/openldap/slapd.d/cn=config +RUN cp -pr ${SLAPD_CONFIG} ${SLAPD_CONFIG}.orig + +COPY init /sbin/ + # Starting -ENTRYPOINT [ "/usr/sbin/slapd" ] -CMD [ "-u","ldap","-h","ldapi:/// ldap:/// ldaps:///","-d","256" ] +ENTRYPOINT [ "/sbin/init" ] EXPOSE 389 636 diff --git a/init b/init index 8ac9b3b..920922f 100755 --- a/init +++ b/init @@ -2,18 +2,39 @@ set -e NAME="OPENLDAP" +SLAPD_CONFIG=${SLAPD_CONFIG:-"/etc/openldap/slapd.d/cn=config"} function stop { echo "Stopping ${NAME}" kill $(cat /var/run/openldap/slapd.pid) } +function mp() { + set +e + mountpoint -q $1 + local mp=$? + set -e + return ${mp} +} + trap 'stop' SIGTERM -if [ "$1" == "start" ]; then +if [ -z "$@" ]; then 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 + [ -x /usr/sbin/slapd ] && /usr/sbin/slapd -u ldap -h "${SLAPD_URLS}" $SLAPD_OPTIONS & wait else