Enabled /sbin/init, check for mounted config path and populate with a default if it is blank

This commit is contained in:
Deon George 2023-05-19 15:30:02 +10:00
parent 676c31a27a
commit c8d3ee19ce
2 changed files with 28 additions and 3 deletions

View File

@ -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

23
init
View File

@ -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