From dc608cf62e5f16dced4fb6ff2e2b5b631227c52c Mon Sep 17 00:00:00 2001 From: jmoore Date: Thu, 15 Mar 2018 08:22:21 +0000 Subject: [PATCH 1/8] Use /var/lib/apacheds as the data volume --- Dockerfile | 6 +++++- README.md | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 89c7d2d..1a9c903 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,10 +9,11 @@ ENV APACHEDS_VERSION 2.0.0-M24 ENV APACHEDS_ARCH amd64 ENV APACHEDS_ARCHIVE apacheds-${APACHEDS_VERSION}-${APACHEDS_ARCH}.deb -ENV APACHEDS_DATA /var/lib/apacheds-${APACHEDS_VERSION} +ENV APACHEDS_DATA /var/lib/apacheds ENV APACHEDS_USER apacheds ENV APACHEDS_GROUP apacheds +RUN ln -s ${APACHEDS_DATA}-${APACHEDS_VERSION} ${APACHDS_DATA} VOLUME ${APACHEDS_DATA} RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections \ @@ -56,4 +57,7 @@ RUN mkdir ${APACHEDS_BOOTSTRAP}/cache \ # ApacheDS wrapper command ############################################# +# Correct for hard-coded INSTANCES_DIRECTORY variable +RUN sed -i 's#/var/lib/apacheds-2.0.0-M24#/var/lib/apacheds#' /opt/apacheds-${APACHEDS_VERSION}/bin/apacheds + CMD ${APACHEDS_CMD} diff --git a/README.md b/README.md index 9eef642..4944d6b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The project sources can be found on [GitHub](https://github.com/openmicroscopy/a ## Installation -The folder */var/lib/apacheds-${APACHEDS_VERSION}* contains the runtime data and thus has been defined as a volume. A [volume container](https://docs.docker.com/userguide/dockervolumes/) could be used for that. The image uses exactly the file system structure defined by the [ApacheDS documentation](https://directory.apache.org/apacheds/advanced-ug/2.2.1-debian-instance-layout.html). +The folder */var/lib/apacheds* contains the runtime data and thus has been defined as a volume. A [volume container](https://docs.docker.com/userguide/dockervolumes/) could be used for that. The image uses exactly the file system structure defined by the [ApacheDS documentation](https://directory.apache.org/apacheds/advanced-ug/2.2.1-debian-instance-layout.html). The container can be started issuing the following command: From 025d65acb04b8dc4a6c06fe7528ca27c9ef24631 Mon Sep 17 00:00:00 2001 From: jmoore Date: Thu, 15 Mar 2018 08:22:33 +0000 Subject: [PATCH 2/8] Install ldapmanager globally in image --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 1a9c903..dbdb51d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,6 +53,9 @@ RUN mkdir ${APACHEDS_BOOTSTRAP}/cache \ && mkdir ${APACHEDS_BOOTSTRAP}/partitions \ && chown -R ${APACHEDS_USER}:${APACHEDS_GROUP} ${APACHEDS_BOOTSTRAP} +RUN apt-get install -y python-ldap +ADD bin/ldapmanager /usr/local/bin/ldapmanager + ############################################# # ApacheDS wrapper command ############################################# From e5d93f6261c36dd3ac321f868733957c00f45ad0 Mon Sep 17 00:00:00 2001 From: jmoore Date: Thu, 15 Mar 2018 08:36:31 +0000 Subject: [PATCH 3/8] Add dumb-init for signal handling --- Dockerfile | 7 ++++++- scripts/run.sh | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index dbdb51d..479b981 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,4 +63,9 @@ ADD bin/ldapmanager /usr/local/bin/ldapmanager # Correct for hard-coded INSTANCES_DIRECTORY variable RUN sed -i 's#/var/lib/apacheds-2.0.0-M24#/var/lib/apacheds#' /opt/apacheds-${APACHEDS_VERSION}/bin/apacheds -CMD ${APACHEDS_CMD} + +RUN curl -L -o /usr/local/bin/dumb-init \ + https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 && \ + chmod +x /usr/local/bin/dumb-init + +ENTRYPOINT ["/run.sh"] diff --git a/scripts/run.sh b/scripts/run.sh index 8006bd9..23a140f 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/local/bin/dumb-init /bin/bash # Environment variables: # APACHEDS_VERSION @@ -18,4 +18,4 @@ if [ ! -d ${APACHEDS_INSTANCE_DIRECTORY} ]; then fi # Execute the server in console mode and not as a daemon. -/opt/apacheds-${APACHEDS_VERSION}/bin/apacheds console ${APACHEDS_INSTANCE} +exec /opt/apacheds-${APACHEDS_VERSION}/bin/apacheds console ${APACHEDS_INSTANCE} From 3c7916edb4abec8df80a466d93c42ea465ba0f7a Mon Sep 17 00:00:00 2001 From: jmoore Date: Thu, 15 Mar 2018 08:38:51 +0000 Subject: [PATCH 4/8] Cleanup pid after console exits --- scripts/run.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/run.sh b/scripts/run.sh index 23a140f..b9d80fc 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -17,5 +17,17 @@ if [ ! -d ${APACHEDS_INSTANCE_DIRECTORY} ]; then chown -v -R ${APACHEDS_USER}:${APACHEDS_GROUP} ${APACHEDS_INSTANCE_DIRECTORY} fi +cleanup(){ + PIDFILE="${APACHEDS_INSTANCE_DIRECTORY}/run/apacheds-${APACHEDS_INSTANCE}.pid" + if [ -e "${PIDFILE}" ]; + then + echo "Cleaning up ${PIDFILE}" + rm "${PIDFILE}" + fi +} + +cleanup +trap cleanup EXIT + # Execute the server in console mode and not as a daemon. -exec /opt/apacheds-${APACHEDS_VERSION}/bin/apacheds console ${APACHEDS_INSTANCE} +/opt/apacheds-${APACHEDS_VERSION}/bin/apacheds console ${APACHEDS_INSTANCE} From 9fef36fa10a4676e9a01158d00989ee4fffae06e Mon Sep 17 00:00:00 2001 From: jmoore Date: Thu, 15 Mar 2018 08:59:32 +0000 Subject: [PATCH 5/8] Attempt clean shutdown --- scripts/run.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/run.sh b/scripts/run.sh index b9d80fc..3c2d2bc 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -26,8 +26,14 @@ cleanup(){ fi } -cleanup +shutdown(){ + echo "Shutting down..." + /opt/apacheds-${APACHEDS_VERSION}/bin/apacheds stop ${APACHEDS_INSTANCE} +} + +trap shutdown TERM trap cleanup EXIT +cleanup # Execute the server in console mode and not as a daemon. -/opt/apacheds-${APACHEDS_VERSION}/bin/apacheds console ${APACHEDS_INSTANCE} +/opt/apacheds-${APACHEDS_VERSION}/bin/apacheds repair ${APACHEDS_INSTANCE} From 3014a42ee3123d8034c29fca624f8b5f166f69e5 Mon Sep 17 00:00:00 2001 From: jmoore Date: Thu, 15 Mar 2018 10:02:17 +0000 Subject: [PATCH 6/8] Use `start` and `stop` to prevent DB corruption --- scripts/run.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/run.sh b/scripts/run.sh index 3c2d2bc..4036981 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -9,6 +9,7 @@ # APACHEDS_GROUP APACHEDS_INSTANCE_DIRECTORY=${APACHEDS_DATA}/${APACHEDS_INSTANCE} +PIDFILE="${APACHEDS_INSTANCE_DIRECTORY}/run/apacheds-${APACHEDS_INSTANCE}.pid" # When a fresh data folder is detected then bootstrap the instance configuration. if [ ! -d ${APACHEDS_INSTANCE_DIRECTORY} ]; then @@ -18,7 +19,6 @@ if [ ! -d ${APACHEDS_INSTANCE_DIRECTORY} ]; then fi cleanup(){ - PIDFILE="${APACHEDS_INSTANCE_DIRECTORY}/run/apacheds-${APACHEDS_INSTANCE}.pid" if [ -e "${PIDFILE}" ]; then echo "Cleaning up ${PIDFILE}" @@ -26,14 +26,16 @@ cleanup(){ fi } +trap cleanup EXIT +cleanup + +/opt/apacheds-${APACHEDS_VERSION}/bin/apacheds start ${APACHEDS_INSTANCE} +sleep 2 # Wait on new pid + shutdown(){ echo "Shutting down..." /opt/apacheds-${APACHEDS_VERSION}/bin/apacheds stop ${APACHEDS_INSTANCE} } -trap shutdown TERM -trap cleanup EXIT -cleanup - -# Execute the server in console mode and not as a daemon. -/opt/apacheds-${APACHEDS_VERSION}/bin/apacheds repair ${APACHEDS_INSTANCE} +trap shutdown INT TERM +tail --pid=$(cat $PIDFILE) -f /dev/null From dc382bad0c586046018bac323255b03ea127d38c Mon Sep 17 00:00:00 2001 From: jmoore Date: Thu, 15 Mar 2018 10:10:21 +0000 Subject: [PATCH 7/8] Minor cleanup of hard-coded version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 479b981..f0526f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,7 +61,7 @@ ADD bin/ldapmanager /usr/local/bin/ldapmanager ############################################# # Correct for hard-coded INSTANCES_DIRECTORY variable -RUN sed -i 's#/var/lib/apacheds-2.0.0-M24#/var/lib/apacheds#' /opt/apacheds-${APACHEDS_VERSION}/bin/apacheds +RUN sed -i "s#/var/lib/apacheds-${APACHEDS_VERSION}#/var/lib/apacheds#" /opt/apacheds-${APACHEDS_VERSION}/bin/apacheds RUN curl -L -o /usr/local/bin/dumb-init \ From 5e02663c7d4c8cb9476a8ff4c04704b71fcd1901 Mon Sep 17 00:00:00 2001 From: jmoore Date: Fri, 16 Mar 2018 18:37:58 +0000 Subject: [PATCH 8/8] Improvements from Simon --- Dockerfile | 10 ++++------ README.md | 2 +- scripts/run.sh | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index f0526f2..5e01e19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ENV APACHEDS_DATA /var/lib/apacheds ENV APACHEDS_USER apacheds ENV APACHEDS_GROUP apacheds -RUN ln -s ${APACHEDS_DATA}-${APACHEDS_VERSION} ${APACHDS_DATA} +RUN ln -s ${APACHEDS_DATA}-${APACHEDS_VERSION} ${APACHEDS_DATA} VOLUME ${APACHEDS_DATA} RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections \ @@ -39,11 +39,9 @@ EXPOSE 10389 10636 60088 60464 8080 8443 ENV APACHEDS_INSTANCE default ENV APACHEDS_BOOTSTRAP /bootstrap -ENV APACHEDS_SCRIPT run.sh -ENV APACHEDS_CMD /${APACHEDS_SCRIPT} -ADD scripts/${APACHEDS_SCRIPT} ${APACHEDS_CMD} -RUN chown ${APACHEDS_USER}:${APACHEDS_GROUP} ${APACHEDS_CMD} \ - && chmod u+rx ${APACHEDS_CMD} +ADD scripts/run.sh /run.sh +RUN chown ${APACHEDS_USER}:${APACHEDS_GROUP} /run.sh \ + && chmod u+rx /run.sh ADD instance/* ${APACHEDS_BOOTSTRAP}/conf/ ADD ome.ldif ${APACHEDS_BOOTSTRAP}/ diff --git a/README.md b/README.md index 4944d6b..991bbe3 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The project sources can be found on [GitHub](https://github.com/openmicroscopy/a ## Installation -The folder */var/lib/apacheds* contains the runtime data and thus has been defined as a volume. A [volume container](https://docs.docker.com/userguide/dockervolumes/) could be used for that. The image uses exactly the file system structure defined by the [ApacheDS documentation](https://directory.apache.org/apacheds/advanced-ug/2.2.1-debian-instance-layout.html). +The folder */var/lib/apacheds* contains the runtime data and thus has been defined as a volume. The image uses exactly the file system structure defined by the [ApacheDS documentation](https://directory.apache.org/apacheds/advanced-ug/2.2.1-debian-instance-layout.html). The container can be started issuing the following command: diff --git a/scripts/run.sh b/scripts/run.sh index 4036981..d3cd204 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -38,4 +38,4 @@ shutdown(){ } trap shutdown INT TERM -tail --pid=$(cat $PIDFILE) -f /dev/null +tail -n 0 --pid=$(cat $PIDFILE) -f ${APACHEDS_INSTANCE_DIRECTORY}/log/apacheds.log