diff --git a/Dockerfile b/Dockerfile index 5589bc8..c1d5dc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,10 +50,11 @@ RUN set -x && \ TEMP_PACKAGES+=(curl) && \ TEMP_PACKAGES+=(file) && \ TEMP_PACKAGES+=(gnupg2) && \ + TEMP_PACKAGES+=(xz-utils) && \ + # Dependencies for healthcheck + KEPT_PACKAGES+=(iproute2) && \ # Better logging KEPT_PACKAGES+=(gawk) && \ - # Dependencies for healthcheck - KEPT_PACKAGES+=(net-tools) && \ # Install packages apt-get update && \ apt-get install --no-install-recommends -y \ @@ -75,24 +76,11 @@ RUN set -x && \ pushd /src/mlat-client && \ ./setup.py build && \ ./setup.py install && \ - # cp -v ./mlat-client /usr/local/bin/mlat-client && \ popd && \ - # Deploy s6-overlay. - curl -s --location -o /tmp/deploy-s6-overlay.sh https://raw.githubusercontent.com/mikenye/deploy-s6-overlay/master/deploy-s6-overlay.sh && \ + # Deploy s6-overlay + curl -o /tmp/deploy-s6-overlay.sh -s https://raw.githubusercontent.com/mikenye/deploy-s6-overlay/master/deploy-s6-overlay-v3.sh && \ bash /tmp/deploy-s6-overlay.sh && \ - # Install - # Deploy healthchecks framework - git clone \ - --depth=1 \ - https://github.com/mikenye/docker-healthchecks-framework.git \ - /opt/healthchecks-framework \ - && \ - rm -rf \ - /opt/healthchecks-framework/.git* \ - /opt/healthchecks-framework/*.md \ - /opt/healthchecks-framework/tests \ - && \ - # Clean-up. + # Clean-up apt-get remove -y ${TEMP_PACKAGES[@]} && \ apt-get autoremove -y && \ rm -rf /src/* /tmp/* /var/lib/apt/lists/* && \ @@ -100,7 +88,7 @@ RUN set -x && \ # Simple tests mlat-client --help && \ pw-feeder --version && \ - # Document versions. + # Document versions set +o pipefail && \ cat /PW_FEEDER_VERSION @@ -108,4 +96,4 @@ COPY rootfs/ / ENTRYPOINT [ "/init" ] -HEALTHCHECK --interval=300s --timeout=5s --start-period=60s --retries=3 CMD /scripts/healthcheck.sh +HEALTHCHECK --interval=300s --timeout=15s --start-period=60s --retries=3 CMD bash /scripts/healthcheck.sh diff --git a/rootfs/etc/cont-init.d/01-timezone b/rootfs/etc/cont-init.d/01-timezone deleted file mode 100755 index 6c378e0..0000000 --- a/rootfs/etc/cont-init.d/01-timezone +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/with-contenv bash -# shellcheck shell=bash - -NOCOLOR='\033[0m' -YELLOW='\033[1;33m' - -# Set up timezone -if [ -z "${TZ}" ]; then - echo -e "${YELLOW}WARNING: TZ environment variable not set${NOCOLOR}" -else - ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone -fi diff --git a/rootfs/etc/s6-overlay/s6-rc.d/initialise/dependencies.d/base b/rootfs/etc/s6-overlay/s6-rc.d/initialise/dependencies.d/base new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/initialise/type b/rootfs/etc/s6-overlay/s6-rc.d/initialise/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/initialise/type @@ -0,0 +1 @@ +oneshot diff --git a/rootfs/etc/s6-overlay/s6-rc.d/initialise/up b/rootfs/etc/s6-overlay/s6-rc.d/initialise/up new file mode 100644 index 0000000..bc27d96 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/initialise/up @@ -0,0 +1,4 @@ +#!/command/with-contenv bash +#shellcheck shell=bash + +exec /scripts/initialise.sh \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/dependencies.d/base b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/dependencies.d/base new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/dependencies.d/initialise b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/dependencies.d/initialise new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/dependencies.d/pw-feeder b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/dependencies.d/pw-feeder new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run new file mode 100644 index 0000000..c06c5a2 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run @@ -0,0 +1,4 @@ +#!/command/with-contenv bash +#shellcheck shell=bash + +exec /scripts/mlat-client.sh \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/type b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/type @@ -0,0 +1 @@ +longrun diff --git a/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/dependencies.d/base b/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/dependencies.d/base new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/dependencies.d/initialise b/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/dependencies.d/initialise new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run b/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run new file mode 100644 index 0000000..bb0a86e --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run @@ -0,0 +1,5 @@ +#!/command/with-contenv bash +#shellcheck shell=bash + +fdmove -c 2 1 /usr/local/sbin/pw-feeder + diff --git a/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/type b/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/type @@ -0,0 +1 @@ +longrun diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/initialise b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/initialise new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/mlat-client b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/mlat-client new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/pw-feeder b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/pw-feeder new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/services.d/pw-feeder/run b/rootfs/etc/services.d/pw-feeder/run deleted file mode 100644 index 45024fe..0000000 --- a/rootfs/etc/services.d/pw-feeder/run +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/with-contenv bash -#shellcheck shell=bash - -/usr/local/sbin/pw-feeder -sleep 10 diff --git a/rootfs/scripts/healthcheck.sh b/rootfs/scripts/healthcheck.sh index 32b7d7f..8a8c5cf 100755 --- a/rootfs/scripts/healthcheck.sh +++ b/rootfs/scripts/healthcheck.sh @@ -1,29 +1,66 @@ -#!/usr/bin/with-contenv bash +#!/command/with-contenv bash #shellcheck shell=bash -# Import healthchecks-framework -# shellcheck disable=SC1091 -source /opt/healthchecks-framework/healthchecks.sh - # Prepare EXITCODE variable EXITCODE=0 -echo "Ensure connection to beast provider $BEASTHOST:$BEASTPORT" -if ! check_tcp4_connection_established ANY ANY "$(get_ipv4 "$BEASTHOST")" "$BEASTPORT"; then +# check pw-feeder to beasthost connection +echo -n "pw-feeder connected to $BEASTHOST:$BEASTPORT: " +if ! ss --tcp --processes state established dst "$BEASTHOST" \&\& dport "$BEASTPORT" | grep pw-feeder > /dev/null 2>&1; then EXITCODE=1 + echo "FAIL" +else + echo "OK" fi -PW_FEED_DESTINATION_BEAST_HOST=$(echo "${PW_BEAST_ENDPOINT}" | cut -d: -f1) -PW_FEED_DESTINATION_BEAST_PORT=$(echo "${PW_BEAST_ENDPOINT}" | cut -d: -f2) - -echo "Ensure connection to plane.watch $PW_FEED_DESTINATION_BEAST_HOST:$PW_FEED_DESTINATION_BEAST_PORT" -if ! check_tcp4_connection_established ANY ANY "$(get_ipv4 "$PW_FEED_DESTINATION_BEAST_HOST")" "$PW_FEED_DESTINATION_BEAST_PORT"; then +# check pw-feeder to plane.watch BEAST connection +echo -n "pw-feeder connected to $PW_BEAST_ENDPOINT: " +if ! ss --tcp --processes state established dst "$PW_BEAST_ENDPOINT" | grep pw-feeder > /dev/null 2>&1; then EXITCODE=1 + echo "FAIL" +else + echo "OK" fi -echo "Check service death tally" -if ! check_s6_service_abnormal_death_tally ALL; then - EXITCODE=1 +# if MLAT enabled... +if [[ "${ENABLE_MLAT,,}" == "true" ]]; then + + # check mlat-client to beasthost connection + echo -n "mlat-client connected to $BEASTHOST:$BEASTPORT: " + if ! ss --tcp --processes state established dst "$BEASTHOST" \&\& dport "$BEASTPORT" | grep mlat-client > /dev/null 2>&1; then + EXITCODE=1 + echo "FAIL" + else + echo "OK" + fi + + # check mlat-client to pw-feeder connection + echo -n "mlat-client connected to pw-client ($MLATSERVERHOST:$MLATSERVERPORT): " + if ! ss --tcp --processes state established dst "$MLATSERVERHOST" \&\& dport "$MLATSERVERPORT" | grep mlat-client > /dev/null 2>&1; then + EXITCODE=1 + echo "FAIL" + else + echo "OK" + fi + + # check mlat-client to pw-feeder connection + echo -n "pw-feeder connected to mlat-client: " + if ! ss --tcp --processes state established src "$MLATSERVERHOST" \&\& sport "$MLATSERVERPORT" | grep pw-feeder > /dev/null 2>&1; then + EXITCODE=1 + echo "FAIL" + else + echo "OK" + fi + + # check pw-feeder to plane.watch MLAT connection + echo -n "pw-feeder connected to $PW_MLAT_ENDPOINT: " + if ! ss --tcp --processes state established dst "$PW_MLAT_ENDPOINT" | grep pw-feeder > /dev/null 2>&1; then + EXITCODE=1 + echo "FAIL" + else + echo "OK" + fi + fi exit "$EXITCODE" diff --git a/rootfs/etc/cont-init.d/02-sanity_check b/rootfs/scripts/initialise.sh old mode 100644 new mode 100755 similarity index 74% rename from rootfs/etc/cont-init.d/02-sanity_check rename to rootfs/scripts/initialise.sh index 29898d8..bba1721 --- a/rootfs/etc/cont-init.d/02-sanity_check +++ b/rootfs/scripts/initialise.sh @@ -1,7 +1,6 @@ -#!/usr/bin/with-contenv bash -# shellcheck shell=bash +#!/command/with-contenv bash +#shellcheck shell=bash -# Define bash colours NOCOLOR='\033[0m' LIGHTRED='\033[1;31m' YELLOW='\033[1;33m' @@ -11,6 +10,17 @@ if [[ -n "$DEBUG_LOGGING" ]]; then set -x fi +echo "[init] Setting timezone..." + +# Set up timezone +if [ -z "${TZ}" ]; then + echo -e "${YELLOW}WARNING: TZ environment variable not set${NOCOLOR}" +else + ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone +fi + +echo "[init] Checking environment variables..." + # Check to make sure the correct command line arguments have been set EXITCODE=0 if [ -z "${BEASTHOST}" ]; then @@ -41,4 +51,6 @@ if [ "$EXITCODE" -ne 0 ]; then exit 1 fi +echo "[init] Completed" + exit "$EXITCODE" diff --git a/rootfs/etc/services.d/mlat-client/run b/rootfs/scripts/mlat-client.sh old mode 100644 new mode 100755 similarity index 95% rename from rootfs/etc/services.d/mlat-client/run rename to rootfs/scripts/mlat-client.sh index b74328c..60c9f86 --- a/rootfs/etc/services.d/mlat-client/run +++ b/rootfs/scripts/mlat-client.sh @@ -1,5 +1,5 @@ -#!/usr/bin/with-contenv bash -# shellcheck shell=bash +#!/command/with-contenv bash +#shellcheck shell=bash # If mlat enabled... if [[ "${ENABLE_MLAT,,}" == "true" ]]; then