From 257f6a6041404696905b590fb2ecfaac1c28a69a Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 21:43:02 +0800 Subject: [PATCH 01/12] implement s6-overlay v3 --- Dockerfile | 2 +- rootfs/etc/cont-init.d/01-timezone | 12 ------------ .../s6-rc.d/initialise/dependencies.d/base | 0 .../s6-rc.d/initialise/run} | 8 +++++++- rootfs/etc/s6-overlay/s6-rc.d/initialise/type | 1 + .../s6-rc.d/mlat-client/dependencies.d/base | 0 .../s6-rc.d/mlat-client/dependencies.d/initialise | 0 .../s6-rc.d/mlat-client/dependencies.d/pw-feeder | 0 .../s6-rc.d}/mlat-client/run | 0 rootfs/etc/s6-overlay/s6-rc.d/mlat-client/type | 1 + .../s6-overlay/s6-rc.d/pw-feeder/dependencies.d/base | 0 .../s6-rc.d/pw-feeder/dependencies.d/initialise | 0 rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run | 5 +++++ rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/type | 1 + .../s6-overlay/s6-rc.d/user/contents.d/initialise | 0 .../s6-overlay/s6-rc.d/user/contents.d/mlat-client | 0 .../etc/s6-overlay/s6-rc.d/user/contents.d/pw-feeder | 0 rootfs/etc/services.d/pw-feeder/run | 5 ----- 18 files changed, 16 insertions(+), 19 deletions(-) delete mode 100755 rootfs/etc/cont-init.d/01-timezone create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/initialise/dependencies.d/base rename rootfs/etc/{cont-init.d/02-sanity_check => s6-overlay/s6-rc.d/initialise/run} (84%) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/initialise/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/mlat-client/dependencies.d/base create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/mlat-client/dependencies.d/initialise create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/mlat-client/dependencies.d/pw-feeder rename rootfs/etc/{services.d => s6-overlay/s6-rc.d}/mlat-client/run (100%) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/mlat-client/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/dependencies.d/base create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/dependencies.d/initialise create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/initialise create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/mlat-client create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/pw-feeder delete mode 100644 rootfs/etc/services.d/pw-feeder/run diff --git a/Dockerfile b/Dockerfile index 5589bc8..fdf1495 100644 --- a/Dockerfile +++ b/Dockerfile @@ -78,7 +78,7 @@ RUN set -x && \ # 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 && \ + 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 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/cont-init.d/02-sanity_check b/rootfs/etc/s6-overlay/s6-rc.d/initialise/run similarity index 84% rename from rootfs/etc/cont-init.d/02-sanity_check rename to rootfs/etc/s6-overlay/s6-rc.d/initialise/run index 29898d8..d624272 100644 --- a/rootfs/etc/cont-init.d/02-sanity_check +++ b/rootfs/etc/s6-overlay/s6-rc.d/initialise/run @@ -1,7 +1,6 @@ #!/usr/bin/with-contenv bash # shellcheck shell=bash -# Define bash colours NOCOLOR='\033[0m' LIGHTRED='\033[1;31m' YELLOW='\033[1;33m' @@ -11,6 +10,13 @@ if [[ -n "$DEBUG_LOGGING" ]]; then set -x fi +# 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 + # Check to make sure the correct command line arguments have been set EXITCODE=0 if [ -z "${BEASTHOST}" ]; then 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/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/services.d/mlat-client/run b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run similarity index 100% rename from rootfs/etc/services.d/mlat-client/run rename to rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run 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 From f0cbdbc2e3393cb8d5630396e016ee27c4fd1bd6 Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 21:48:31 +0800 Subject: [PATCH 02/12] fixes --- Dockerfile | 1 + rootfs/etc/s6-overlay/s6-rc.d/initialise/{run => up} | 0 2 files changed, 1 insertion(+) rename rootfs/etc/s6-overlay/s6-rc.d/initialise/{run => up} (100%) diff --git a/Dockerfile b/Dockerfile index fdf1495..286848e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,6 +50,7 @@ RUN set -x && \ TEMP_PACKAGES+=(curl) && \ TEMP_PACKAGES+=(file) && \ TEMP_PACKAGES+=(gnupg2) && \ + TEMP_PACKAGES+=(xz-utils) && \ # Better logging KEPT_PACKAGES+=(gawk) && \ # Dependencies for healthcheck diff --git a/rootfs/etc/s6-overlay/s6-rc.d/initialise/run b/rootfs/etc/s6-overlay/s6-rc.d/initialise/up similarity index 100% rename from rootfs/etc/s6-overlay/s6-rc.d/initialise/run rename to rootfs/etc/s6-overlay/s6-rc.d/initialise/up From 327f3394691e811c4259b97931e7ec705f80310f Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 21:52:43 +0800 Subject: [PATCH 03/12] update shebangs --- rootfs/etc/s6-overlay/s6-rc.d/initialise/up | 4 ++-- rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run | 4 ++-- rootfs/scripts/healthcheck.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rootfs/etc/s6-overlay/s6-rc.d/initialise/up b/rootfs/etc/s6-overlay/s6-rc.d/initialise/up index d624272..30893ef 100644 --- a/rootfs/etc/s6-overlay/s6-rc.d/initialise/up +++ b/rootfs/etc/s6-overlay/s6-rc.d/initialise/up @@ -1,5 +1,5 @@ -#!/usr/bin/with-contenv bash -# shellcheck shell=bash +#!/command/with-contenv bash +#shellcheck shell=bash NOCOLOR='\033[0m' LIGHTRED='\033[1;31m' diff --git a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run index b74328c..60c9f86 100644 --- a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run +++ b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run @@ -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 diff --git a/rootfs/scripts/healthcheck.sh b/rootfs/scripts/healthcheck.sh index 32b7d7f..2cd278f 100755 --- a/rootfs/scripts/healthcheck.sh +++ b/rootfs/scripts/healthcheck.sh @@ -1,4 +1,4 @@ -#!/usr/bin/with-contenv bash +#!/command/with-contenv bash #shellcheck shell=bash # Import healthchecks-framework From 7c0f405891aec05cd7966a7fce59c73495f21f6d Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 21:56:22 +0800 Subject: [PATCH 04/12] shebang --- rootfs/etc/s6-overlay/s6-rc.d/initialise/up | 2 +- rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run | 2 +- rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run | 2 +- rootfs/scripts/healthcheck.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rootfs/etc/s6-overlay/s6-rc.d/initialise/up b/rootfs/etc/s6-overlay/s6-rc.d/initialise/up index 30893ef..e3d56eb 100644 --- a/rootfs/etc/s6-overlay/s6-rc.d/initialise/up +++ b/rootfs/etc/s6-overlay/s6-rc.d/initialise/up @@ -1,4 +1,4 @@ -#!/command/with-contenv bash +#!/bin/bash #shellcheck shell=bash NOCOLOR='\033[0m' diff --git a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run index 60c9f86..95a25fe 100644 --- a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run +++ b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run @@ -1,4 +1,4 @@ -#!/command/with-contenv bash +#!/bin/bash #shellcheck shell=bash # If mlat enabled... diff --git a/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run b/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run index bb0a86e..5347904 100644 --- a/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run +++ b/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run @@ -1,4 +1,4 @@ -#!/command/with-contenv bash +#!/bin/bash #shellcheck shell=bash fdmove -c 2 1 /usr/local/sbin/pw-feeder diff --git a/rootfs/scripts/healthcheck.sh b/rootfs/scripts/healthcheck.sh index 2cd278f..7a90411 100755 --- a/rootfs/scripts/healthcheck.sh +++ b/rootfs/scripts/healthcheck.sh @@ -1,4 +1,4 @@ -#!/command/with-contenv bash +#!/bin/bash #shellcheck shell=bash # Import healthchecks-framework From c6972e0c668bdfe0e5a8104895e662927c2805bb Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 22:06:24 +0800 Subject: [PATCH 05/12] troubleshoot --- rootfs/etc/s6-overlay/s6-rc.d/initialise/up | 50 +------------------ rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run | 41 +-------------- rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run | 2 +- rootfs/scripts/healthcheck.sh | 2 +- rootfs/scripts/initialise.sh | 49 ++++++++++++++++++ rootfs/scripts/mlat-client.sh | 40 +++++++++++++++ 6 files changed, 95 insertions(+), 89 deletions(-) create mode 100644 rootfs/scripts/initialise.sh create mode 100644 rootfs/scripts/mlat-client.sh diff --git a/rootfs/etc/s6-overlay/s6-rc.d/initialise/up b/rootfs/etc/s6-overlay/s6-rc.d/initialise/up index e3d56eb..bc27d96 100644 --- a/rootfs/etc/s6-overlay/s6-rc.d/initialise/up +++ b/rootfs/etc/s6-overlay/s6-rc.d/initialise/up @@ -1,50 +1,4 @@ -#!/bin/bash +#!/command/with-contenv bash #shellcheck shell=bash -NOCOLOR='\033[0m' -LIGHTRED='\033[1;31m' -YELLOW='\033[1;33m' - -# If troubleshooting: -if [[ -n "$DEBUG_LOGGING" ]]; then - set -x -fi - -# 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 - -# Check to make sure the correct command line arguments have been set -EXITCODE=0 -if [ -z "${BEASTHOST}" ]; then - echo -e "${LIGHTRED}ERROR: BEASTHOST environment variable not set${NOCOLOR}" - EXITCODE=1 -fi -if [ -z "${API_KEY}" ]; then - echo -e "${LIGHTRED}ERROR: API_KEY environment variable was not set${NOCOLOR}" - EXITCODE=1 -fi - -# If mlat enabled... -if [[ "${ENABLE_MLAT,,}" == "true" ]]; then - # ... make sure that the correct env vars are set - if [ -z "$LAT" ]; then - echo -e "${YELLOW}WARNING: No LAT environment variable, cannot use MLAT${NOCOLOR}" - fi - if [ -z "$LONG" ]; then - echo -e "${YELLOW}WARNING: No LONG environment variable, cannot use MLAT${NOCOLOR}" - fi - if [ -z "$ALT" ]; then - echo -e "${YELLOW}WARNING: No ALT environment variable, cannot use MLAT${NOCOLOR}" - fi -fi - -# If any errors above are fatal, don't proceed starting the container -if [ "$EXITCODE" -ne 0 ]; then - exit 1 -fi - -exit "$EXITCODE" +exec /scripts/initialise.sh \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run index 95a25fe..c06c5a2 100644 --- a/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run +++ b/rootfs/etc/s6-overlay/s6-rc.d/mlat-client/run @@ -1,41 +1,4 @@ -#!/bin/bash +#!/command/with-contenv bash #shellcheck shell=bash -# If mlat enabled... -if [[ "${ENABLE_MLAT,,}" == "true" ]]; then - - # Make sure we have the needed env vars - if [[ -n "$LAT" ]] && [[ -n "$LONG" ]] && [[ -n "$ALT" ]]; then - - # shellcheck disable=SC2015 - [[ -z "${MLAT_DATASOURCE}" ]] && MLAT_DATASOURCE="${BEASTHOST}:${BEASTPORT}" || true - - # give other stuff some time to come up - sleep 5 - - # Launch mlat-client - # shellcheck disable=SC2016 - /usr/local/bin/mlat-client \ - --input-type "$MLAT_INPUT_TYPE" \ - --input-connect "${MLAT_DATASOURCE}" \ - --lat "$LAT" \ - --lon "$LONG" \ - --alt "${ALT}" \ - --results "beast,listen,30105" \ - --server "${MLATSERVERHOST}:${MLATSERVERPORT}" \ - --user "${API_KEY}" \ - 2>&1 \ - | stdbuf -o0 sed --unbuffered '/^$/d' \ - | stdbuf -o0 sed --unbuffered '/^ .*/d' \ - | stdbuf -o0 awk '{print "[mlat-client] " $0}' - - else - - sleep infinity - - fi - -# If not enabled, sleep forever -else - sleep infinity -fi +exec /scripts/mlat-client.sh \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run b/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run index 5347904..bb0a86e 100644 --- a/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run +++ b/rootfs/etc/s6-overlay/s6-rc.d/pw-feeder/run @@ -1,4 +1,4 @@ -#!/bin/bash +#!/command/with-contenv bash #shellcheck shell=bash fdmove -c 2 1 /usr/local/sbin/pw-feeder diff --git a/rootfs/scripts/healthcheck.sh b/rootfs/scripts/healthcheck.sh index 7a90411..2cd278f 100755 --- a/rootfs/scripts/healthcheck.sh +++ b/rootfs/scripts/healthcheck.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/command/with-contenv bash #shellcheck shell=bash # Import healthchecks-framework diff --git a/rootfs/scripts/initialise.sh b/rootfs/scripts/initialise.sh new file mode 100644 index 0000000..fdca4a2 --- /dev/null +++ b/rootfs/scripts/initialise.sh @@ -0,0 +1,49 @@ +#!/command/with-contenv bash + +NOCOLOR='\033[0m' +LIGHTRED='\033[1;31m' +YELLOW='\033[1;33m' + +# If troubleshooting: +if [[ -n "$DEBUG_LOGGING" ]]; then + set -x +fi + +# 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 + +# Check to make sure the correct command line arguments have been set +EXITCODE=0 +if [ -z "${BEASTHOST}" ]; then + echo -e "${LIGHTRED}ERROR: BEASTHOST environment variable not set${NOCOLOR}" + EXITCODE=1 +fi +if [ -z "${API_KEY}" ]; then + echo -e "${LIGHTRED}ERROR: API_KEY environment variable was not set${NOCOLOR}" + EXITCODE=1 +fi + +# If mlat enabled... +if [[ "${ENABLE_MLAT,,}" == "true" ]]; then + # ... make sure that the correct env vars are set + if [ -z "$LAT" ]; then + echo -e "${YELLOW}WARNING: No LAT environment variable, cannot use MLAT${NOCOLOR}" + fi + if [ -z "$LONG" ]; then + echo -e "${YELLOW}WARNING: No LONG environment variable, cannot use MLAT${NOCOLOR}" + fi + if [ -z "$ALT" ]; then + echo -e "${YELLOW}WARNING: No ALT environment variable, cannot use MLAT${NOCOLOR}" + fi +fi + +# If any errors above are fatal, don't proceed starting the container +if [ "$EXITCODE" -ne 0 ]; then + exit 1 +fi + +exit "$EXITCODE" diff --git a/rootfs/scripts/mlat-client.sh b/rootfs/scripts/mlat-client.sh new file mode 100644 index 0000000..d6e8ce6 --- /dev/null +++ b/rootfs/scripts/mlat-client.sh @@ -0,0 +1,40 @@ +#!/command/with-contenv bash + +# If mlat enabled... +if [[ "${ENABLE_MLAT,,}" == "true" ]]; then + + # Make sure we have the needed env vars + if [[ -n "$LAT" ]] && [[ -n "$LONG" ]] && [[ -n "$ALT" ]]; then + + # shellcheck disable=SC2015 + [[ -z "${MLAT_DATASOURCE}" ]] && MLAT_DATASOURCE="${BEASTHOST}:${BEASTPORT}" || true + + # give other stuff some time to come up + sleep 5 + + # Launch mlat-client + # shellcheck disable=SC2016 + /usr/local/bin/mlat-client \ + --input-type "$MLAT_INPUT_TYPE" \ + --input-connect "${MLAT_DATASOURCE}" \ + --lat "$LAT" \ + --lon "$LONG" \ + --alt "${ALT}" \ + --results "beast,listen,30105" \ + --server "${MLATSERVERHOST}:${MLATSERVERPORT}" \ + --user "${API_KEY}" \ + 2>&1 \ + | stdbuf -o0 sed --unbuffered '/^$/d' \ + | stdbuf -o0 sed --unbuffered '/^ .*/d' \ + | stdbuf -o0 awk '{print "[mlat-client] " $0}' + + else + + sleep infinity + + fi + +# If not enabled, sleep forever +else + sleep infinity +fi From e0ab07b5a5507801aeb97cdbfdc1968ea81410a3 Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 22:08:14 +0800 Subject: [PATCH 06/12] chmod --- rootfs/scripts/initialise.sh | 0 rootfs/scripts/mlat-client.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 rootfs/scripts/initialise.sh mode change 100644 => 100755 rootfs/scripts/mlat-client.sh diff --git a/rootfs/scripts/initialise.sh b/rootfs/scripts/initialise.sh old mode 100644 new mode 100755 diff --git a/rootfs/scripts/mlat-client.sh b/rootfs/scripts/mlat-client.sh old mode 100644 new mode 100755 From 05c45bbfd6d7fc3e35cf47118eb12f9e79447195 Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 22:10:10 +0800 Subject: [PATCH 07/12] . --- rootfs/scripts/initialise.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rootfs/scripts/initialise.sh b/rootfs/scripts/initialise.sh index fdca4a2..a180a78 100755 --- a/rootfs/scripts/initialise.sh +++ b/rootfs/scripts/initialise.sh @@ -9,6 +9,8 @@ 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}" @@ -16,6 +18,8 @@ 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 @@ -46,4 +50,6 @@ if [ "$EXITCODE" -ne 0 ]; then exit 1 fi +echo "[init] Completed" + exit "$EXITCODE" From 15026ddcd7921a070399098d462c1768231dd263 Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 22:14:18 +0800 Subject: [PATCH 08/12] remove healthcheck scripts --- Dockerfile | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 286848e..ae2a4db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,8 +53,6 @@ RUN set -x && \ TEMP_PACKAGES+=(xz-utils) && \ # Better logging KEPT_PACKAGES+=(gawk) && \ - # Dependencies for healthcheck - KEPT_PACKAGES+=(net-tools) && \ # Install packages apt-get update && \ apt-get install --no-install-recommends -y \ @@ -76,24 +74,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. + # 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/* && \ @@ -101,7 +86,7 @@ RUN set -x && \ # Simple tests mlat-client --help && \ pw-feeder --version && \ - # Document versions. + # Document versions set +o pipefail && \ cat /PW_FEEDER_VERSION From bd31ebb70c2162292045c44ef5dd0b27b73aaf3c Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 22:41:47 +0800 Subject: [PATCH 09/12] healthcheck --- rootfs/scripts/healthcheck.sh | 65 +++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/rootfs/scripts/healthcheck.sh b/rootfs/scripts/healthcheck.sh index 2cd278f..3a0af2a 100755 --- a/rootfs/scripts/healthcheck.sh +++ b/rootfs/scripts/healthcheck.sh @@ -1,29 +1,66 @@ #!/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" From ad61ebdf2c9aaf56ce50b46f6e6f9a6152703760 Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 22:46:08 +0800 Subject: [PATCH 10/12] healthcheck --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ae2a4db..03e98d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,6 +51,8 @@ RUN set -x && \ TEMP_PACKAGES+=(file) && \ TEMP_PACKAGES+=(gnupg2) && \ TEMP_PACKAGES+=(xz-utils) && \ + # Dependencies for healthcheck + KEPT_PACKAGES+=(iproute2) && \ # Better logging KEPT_PACKAGES+=(gawk) && \ # Install packages @@ -94,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=5s --start-period=60s --retries=3 CMD bash /scripts/healthcheck.sh From a5eb9c69e6b7fca990f2aa32b3a37cf1b5e7cb98 Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 22:52:57 +0800 Subject: [PATCH 11/12] adjust timeout --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 03e98d5..c1d5dc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -96,4 +96,4 @@ COPY rootfs/ / ENTRYPOINT [ "/init" ] -HEALTHCHECK --interval=300s --timeout=5s --start-period=60s --retries=3 CMD bash /scripts/healthcheck.sh +HEALTHCHECK --interval=300s --timeout=15s --start-period=60s --retries=3 CMD bash /scripts/healthcheck.sh From b1c0e2b222c5651a239fc7ef51af85ee15548ffb Mon Sep 17 00:00:00 2001 From: Mike Nye Date: Sat, 27 Jan 2024 23:19:16 +0800 Subject: [PATCH 12/12] linting --- rootfs/scripts/healthcheck.sh | 2 +- rootfs/scripts/initialise.sh | 1 + rootfs/scripts/mlat-client.sh | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rootfs/scripts/healthcheck.sh b/rootfs/scripts/healthcheck.sh index 3a0af2a..8a8c5cf 100755 --- a/rootfs/scripts/healthcheck.sh +++ b/rootfs/scripts/healthcheck.sh @@ -54,7 +54,7 @@ if [[ "${ENABLE_MLAT,,}" == "true" ]]; then # 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 + if ! ss --tcp --processes state established dst "$PW_MLAT_ENDPOINT" | grep pw-feeder > /dev/null 2>&1; then EXITCODE=1 echo "FAIL" else diff --git a/rootfs/scripts/initialise.sh b/rootfs/scripts/initialise.sh index a180a78..bba1721 100755 --- a/rootfs/scripts/initialise.sh +++ b/rootfs/scripts/initialise.sh @@ -1,4 +1,5 @@ #!/command/with-contenv bash +#shellcheck shell=bash NOCOLOR='\033[0m' LIGHTRED='\033[1;31m' diff --git a/rootfs/scripts/mlat-client.sh b/rootfs/scripts/mlat-client.sh index d6e8ce6..60c9f86 100755 --- a/rootfs/scripts/mlat-client.sh +++ b/rootfs/scripts/mlat-client.sh @@ -1,4 +1,5 @@ #!/command/with-contenv bash +#shellcheck shell=bash # If mlat enabled... if [[ "${ENABLE_MLAT,,}" == "true" ]]; then