From 79f85cc94c643d04d5c9777a546056a62ba2036a Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sat, 4 Feb 2017 14:09:01 +0000 Subject: [PATCH] Add tini, rename entry point, and allow running sh directly --- full/znc-build-modules.sh | 4 ++-- small/Dockerfile | 5 +++-- small/docker-entrypoint.sh | 26 ++++++++++++++++++++++++++ small/znc-entrypoint.sh | 16 ---------------- 4 files changed, 31 insertions(+), 20 deletions(-) create mode 100755 small/docker-entrypoint.sh delete mode 100755 small/znc-entrypoint.sh diff --git a/full/znc-build-modules.sh b/full/znc-build-modules.sh index 3be0482..ea87d1b 100755 --- a/full/znc-build-modules.sh +++ b/full/znc-build-modules.sh @@ -2,7 +2,7 @@ # Build modules from source. if [ -d "${DATADIR}/modules" ]; then - cd "${DATADIR}/modules" || exit 1 + cd "${DATADIR}/modules" || exit 11 # Find module sources. modules=$(find . -name "*.cpp") @@ -10,7 +10,7 @@ if [ -d "${DATADIR}/modules" ]; then if [ -n "$modules" ]; then # Build modules. echo "Building modules $modules..." - /opt/znc/bin/znc-buildmod $modules || exit 1 + /opt/znc/bin/znc-buildmod $modules || exit 12 fi fi diff --git a/small/Dockerfile b/small/Dockerfile index cae5209..f69ffa0 100644 --- a/small/Dockerfile +++ b/small/Dockerfile @@ -14,6 +14,7 @@ RUN set -x \ && adduser -S znc \ && addgroup -S znc \ && apk add --no-cache --virtual runtime-dependencies \ + tini \ icu \ openssl \ cyrus-sasl \ @@ -41,11 +42,11 @@ RUN set -x \ && apk del build-dependencies \ && cd / && rm -Rf /znc-src -COPY znc-entrypoint.sh / +COPY docker-entrypoint.sh / USER znc VOLUME /znc-data EXPOSE 6667 -ENTRYPOINT ["/znc-entrypoint.sh"] +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/small/docker-entrypoint.sh b/small/docker-entrypoint.sh new file mode 100755 index 0000000..b3811db --- /dev/null +++ b/small/docker-entrypoint.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# "docker run -ti znc sh" should work, according to +# https://github.com/docker-library/official-images +if [ "${1:0:1}" != '-' ]; then + exec "$@" +fi + +# Options. +DATADIR="/znc-data" + +# Make sure $DATADIR is owned by znc user. This effects ownership of the +# mounted directory on the host machine too. +chown -R znc:znc "$DATADIR" || exit 1 +chmod 700 "$DATADIR" || exit 2 + +# This file is added by znc:full image +if [ -r /znc-build-modules.sh ]; then + source /znc-build-modules.sh || exit 3 +fi + +cd / + +# ZNC itself responds to SIGTERM, and reaps its children, but whatever was +# started via *shell module is not guaranteed to reap their children. +exec /sbin/tini -- /opt/znc/bin/znc --foreground --datadir "$DATADIR" "$@" diff --git a/small/znc-entrypoint.sh b/small/znc-entrypoint.sh deleted file mode 100755 index 1b1b30c..0000000 --- a/small/znc-entrypoint.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -# Options. -export DATADIR="/znc-data" - -# Make sure $DATADIR is owned by znc user. This effects ownership of the -# mounted directory on the host machine too. -chown -R znc:znc "$DATADIR" || exit 1 -chmod 700 "$DATADIR" || exit 2 - -# Added by znc:full image -if [ -r /znc-build-modules.sh ]; then - /znc-build-modules.sh || exit 3 -fi - -exec /opt/znc/bin/znc --foreground --datadir /znc-data "$@"