Skip to content

Commit

Permalink
Upgrade s6 overlay to v3 (#23)
Browse files Browse the repository at this point in the history
* implement s6-overlay v3
* adjust healthcheck
  • Loading branch information
mikenye authored Jan 27, 2024
1 parent 78d385f commit df1767c
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 57 deletions.
28 changes: 8 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -75,37 +76,24 @@ 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/* && \
find /var/log -type f -exec truncate --size=0 {} \; && \
# Simple tests
mlat-client --help && \
pw-feeder --version && \
# Document versions.
# Document versions
set +o pipefail && \
cat /PW_FEEDER_VERSION

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
12 changes: 0 additions & 12 deletions rootfs/etc/cont-init.d/01-timezone

This file was deleted.

Empty file.
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/initialise/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
4 changes: 4 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/initialise/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/command/with-contenv bash
#shellcheck shell=bash

exec /scripts/initialise.sh
Empty file.
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/command/with-contenv bash
#shellcheck shell=bash

exec /scripts/mlat-client.sh
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/mlat-client/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/command/with-contenv bash
#shellcheck shell=bash

fdmove -c 2 1 /usr/local/sbin/pw-feeder

1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.
5 changes: 0 additions & 5 deletions rootfs/etc/services.d/pw-feeder/run

This file was deleted.

67 changes: 52 additions & 15 deletions rootfs/scripts/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 15 additions & 3 deletions rootfs/etc/cont-init.d/02-sanity_check → rootfs/scripts/initialise.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -41,4 +51,6 @@ if [ "$EXITCODE" -ne 0 ]; then
exit 1
fi

echo "[init] Completed"

exit "$EXITCODE"
4 changes: 2 additions & 2 deletions rootfs/etc/services.d/mlat-client/run → rootfs/scripts/mlat-client.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit df1767c

Please sign in to comment.