From 46d77e811780efec59f815e24ff5b3f0be4c1047 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Fri, 5 May 2023 10:19:22 +0200 Subject: [PATCH 1/3] Revert "fix `s6wrap --quiet`" This reverts commit b69c651cba41cfc2035092df24abe891e778ad96. For smoother merge of following commit that fixes the same issue and does other stuff --- .../cont-init.d/01-print-container-version | 4 +-- rootfs/etc/services.d/mlat-client/run | 34 +++++++++---------- rootfs/etc/services.d/mlathub/run | 20 +++++------ rootfs/etc/services.d/readsb/run | 12 +++---- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/rootfs/etc/cont-init.d/01-print-container-version b/rootfs/etc/cont-init.d/01-print-container-version index c60d169..2301490 100644 --- a/rootfs/etc/cont-init.d/01-print-container-version +++ b/rootfs/etc/cont-init.d/01-print-container-version @@ -20,6 +20,6 @@ source /scripts/common # If not, see . #--------------------------------------------------------------------------------------------- +alias s6wrap='s6wrap --quiet' - -[[ -f /.CONTAINER_VERSION ]] && s6wrap --quiet --prepend=01-print-container-version --timestamps --args echo "Container Version: $(cat /.CONTAINER_VERSION), build date $(stat -c '%y' /.CONTAINER_VERSION |sed 's|\(.*\)\.[0-9]* \(.*\)|\1 \2|g')" || true +[[ -f /.CONTAINER_VERSION ]] && s6wrap --prepend=01-print-container-version --timestamps --args echo "Container Version: $(cat /.CONTAINER_VERSION), build date $(stat -c '%y' /.CONTAINER_VERSION |sed 's|\(.*\)\.[0-9]* \(.*\)|\1 \2|g')" || true diff --git a/rootfs/etc/services.d/mlat-client/run b/rootfs/etc/services.d/mlat-client/run index 132ff45..424cee8 100644 --- a/rootfs/etc/services.d/mlat-client/run +++ b/rootfs/etc/services.d/mlat-client/run @@ -18,9 +18,9 @@ #--------------------------------------------------------------------------------------------- APPNAME="mlat-client" +alias s6wrap='s6wrap --quiet' - -s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "Started as an s6 service" +s6wrap --prepend="${APPNAME}" --timestamps --args echo "Started as an s6 service" source /scripts/common source /scripts/interpret_ultrafeeder_config @@ -32,27 +32,27 @@ declare -A pid_array if [[ -z "${MLAT_CONFIG}" ]] then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "Warning: MLAT_CONFIG not defined - MLAT will be disabled." + s6wrap --prepend="${APPNAME}" --timestamps --args echo "Warning: MLAT_CONFIG not defined - MLAT will be disabled." sleep infinity fi if [[ -z "${MLAT_USER}" ]] && [[ -z "${UUID}" ]] then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "ERROR: either UUID or MLAT_USER must be defined - MLAT will be disabled." + s6wrap --prepend="${APPNAME}" --timestamps --args echo "ERROR: either UUID or MLAT_USER must be defined - MLAT will be disabled." sleep infinity fi if [[ -z "$LAT$READSB_LAT" ]]; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "ERROR: READSB_LAT or LAT must be defined - MLAT will be disabled." + s6wrap --prepend="${APPNAME}" --timestamps --args echo "ERROR: READSB_LAT or LAT must be defined - MLAT will be disabled." sleep infinity fi if [[ -z "$LONG$READSB_LON" ]]; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "ERROR: READSB_LON or LONG must be defined - MLAT will be disabled." + s6wrap --prepend="${APPNAME}" --timestamps --args echo "ERROR: READSB_LON or LONG must be defined - MLAT will be disabled." sleep infinity fi if [[ -z "$ALT$READSB_ALT" ]]; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "ERROR: READSB_ALT or ALT must be defined - MLAT will be disabled." + s6wrap --prepend="${APPNAME}" --timestamps --args echo "ERROR: READSB_ALT or ALT must be defined - MLAT will be disabled." sleep infinity fi @@ -79,7 +79,7 @@ do # Check if the params array has values for the mandatory elements: if [[ -z "${params[0]}" ]] || [[ -z "${params[1]}" ]] then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "ERROR -- MLAT_CONFIG is malformed: \"${instance}\". Stopping MLAT execution." + s6wrap --prepend="${APPNAME}" --timestamps --args echo "ERROR -- MLAT_CONFIG is malformed: \"${instance}\". Stopping MLAT execution." # shellcheck disable=SC2046 kill $(ps -s $$ -o pid=) sleep infinity @@ -134,7 +134,7 @@ do MLAT_PARAM+=(--user "${MLAT_USER}") else rnd="${RANDOM}" - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "WARNING: MLAT_USER is not set - using random number \"${rnd}\" as MLAT_USER" + s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING: MLAT_USER is not set - using random number \"${rnd}\" as MLAT_USER" MLAT_PARAM+=(--user "${rnd}") fi @@ -172,7 +172,7 @@ do # generate a random UUID UUID="$(cat /proc/sys/kernel/random/uuid)" [[ -z "${UUID}" ]] && UUID="$(printf '00000000-ffff-aaaa-%04x-%012x\n' "$RANDOM" "$(date +%s)")" - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "WARNING: UUID is not defined - using randomized uuid \"${UUID}\"" + s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING: UUID is not defined - using randomized uuid \"${UUID}\"" MLAT_PARAM+=("--uuid ${UUID}") fi @@ -187,7 +187,7 @@ do # ------------------------------------------------ # Ready to launch, but wait until readsb is established... if ! pgrep readsb >/dev/null; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "Delaying start of MLAT client(s) until container is established..." + s6wrap --prepend="${APPNAME}" --timestamps --args echo "Delaying start of MLAT client(s) until container is established..." while ! pgrep readsb >/dev/null do sleep 2 @@ -196,13 +196,13 @@ do sleep 10 # sleep a bit so everything is well established - starting readsb may take a bit # run this Mlat_client instance in the background: - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "starting: ${MLAT_CMD} ${MLAT_PARAM[*]}" + s6wrap --prepend="${APPNAME}" --timestamps --args echo "starting: ${MLAT_CMD} ${MLAT_PARAM[*]}" #shellcheck disable=SC2069,SC2086 if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then - { exec s6wrap --quiet --prepend="${APPNAME}][${params[0]}" --timestamps --args ${execstring}; } & + { exec s6wrap --prepend="${APPNAME}][${params[0]}" --timestamps --args ${execstring}; } & elif [[ "${LOGLEVEL,,}" == "error" ]]; then - { exec s6wrap --quiet --prepend="${APPNAME}][${params[0]}" --timestamps --args ${execstring} 2>&1 >/dev/null; } & + { exec s6wrap --prepend="${APPNAME}][${params[0]}" --timestamps --args ${execstring} 2>&1 >/dev/null; } & elif [[ "${LOGLEVEL,,}" == "none" ]]; then { exec ${execstring} >/dev/null 2>/dev/null; } & fi @@ -230,15 +230,15 @@ do servername="$(awk '{print $4}' <<< "${pid_array[$mlat_pid]}")" servername="${servername%%:*}" - [[ "${LOGLEVEL,,}" != "none" ]] && s6wrap --quiet --prepend="${APPNAME}[${servername}" --timestamps --args echo "MLAT_Client ${servername} exited. Attempting to restart." || true + [[ "${LOGLEVEL,,}" != "none" ]] && s6wrap --prepend="${APPNAME}[${servername}" --timestamps --args echo "MLAT_Client ${servername} exited. Attempting to restart." || true # shellcheck disable=SC2086 execstring="$(echo ${MLAT_CMD} ${pid_array[$mlat_pid]} | xargs)" #shellcheck disable=SC2069,SC2086 if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then - { exec s6wrap --quiet --prepend="${APPNAME}][${servername}" --timestamps --args ${execstring} 2>&1; } & + { exec s6wrap --prepend="${APPNAME}][${servername}" --timestamps --args ${execstring} 2>&1; } & elif [[ "${LOGLEVEL,,}" == "error" ]]; then - { exec s6wrap --quiet --prepend="${APPNAME}][${servername}" --timestamps --args ${execstring} 2>&1 >/dev/null; } & + { exec s6wrap --prepend="${APPNAME}][${servername}" --timestamps --args ${execstring} 2>&1 >/dev/null; } & elif [[ "${LOGLEVEL,,}" == "none" ]]; then { exec ${execstring} >/dev/null 2>/dev/null; } & fi diff --git a/rootfs/etc/services.d/mlathub/run b/rootfs/etc/services.d/mlathub/run index 525fc02..7393500 100644 --- a/rootfs/etc/services.d/mlathub/run +++ b/rootfs/etc/services.d/mlathub/run @@ -4,15 +4,15 @@ APPNAME="mlathub" source /scripts/common source /scripts/interpret_ultrafeeder_config - +alias s6wrap='s6wrap --quiet' if [[ -z "${MLAT_CONFIG}" ]] && [[ -z "$MLATHUB_NET_CONNECTOR" ]]; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "No MLAT servers have been defined in MLAT_CONFIG and no external sources have been defined in MLATHUB_NET_CONNECTOR - no need to start MLATHUB" + s6wrap --prepend="${APPNAME}" --timestamps --args echo "No MLAT servers have been defined in MLAT_CONFIG and no external sources have been defined in MLATHUB_NET_CONNECTOR - no need to start MLATHUB" sleep infinity fi if chk_enabled "${MLATHUB_DISABLED}"; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "MLATHUB is disabled." + s6wrap --prepend="${APPNAME}" --timestamps --args echo "MLATHUB is disabled." sleep infinity fi @@ -60,7 +60,7 @@ done if (( mlat_result_sources == 0 )) then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "No MLAT servers have been defined in MLAT_CONFIG - no need to start MLATHUB" + s6wrap --prepend="${APPNAME}" --timestamps --args echo "No MLAT servers have been defined in MLAT_CONFIG - no need to start MLATHUB" sleep infinity fi @@ -110,7 +110,7 @@ MLATHUB_CMD+=("--net-heartbeat=${READSB_NET_HEARTBEAT:-35}") if [[ ! -f /run/mlathub_up ]] then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "Delaying MLAT hub start until container is established..." + s6wrap --prepend="${APPNAME}" --timestamps --args echo "Delaying MLAT hub start until container is established..." while [[ ! -f /run/mlathub_up ]] do sleep 2 @@ -118,16 +118,16 @@ then fi sleep 5 # sleep a bit so everything is well established -s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "Starting MLATHUB..." +s6wrap --prepend="${APPNAME}" --timestamps --args echo "Starting MLATHUB..." # shellcheck disable=SC2086,SC2069 if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS 2>&1 + s6wrap --prepend="${APPNAME}" --timestamps --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS 2>&1 elif [[ "${LOGLEVEL,,}" == "error" ]]; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS 2>&1 >/dev/null + s6wrap --prepend="${APPNAME}" --timestamps --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS 2>&1 >/dev/null elif [[ "${LOGLEVEL,,}" == "none" ]]; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS >/dev/null 2>/dev/null + s6wrap --prepend="${APPNAME}" --timestamps --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS >/dev/null 2>/dev/null fi -s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "WARNING: The mlathub instance has exited. Restarting in 10 seconds." +s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING: The mlathub instance has exited. Restarting in 10 seconds." sleep 10 diff --git a/rootfs/etc/services.d/readsb/run b/rootfs/etc/services.d/readsb/run index b14f691..7c00eb0 100644 --- a/rootfs/etc/services.d/readsb/run +++ b/rootfs/etc/services.d/readsb/run @@ -5,7 +5,7 @@ APPNAME="readsb" source /scripts/common source /scripts/interpret_ultrafeeder_config - +alias s6wrap='s6wrap --quiet' mkdir -p /run/readsb @@ -65,12 +65,12 @@ if ! chk_enabled "$READSB_NET_SBS_DISABLE_REDUCE"; then fi if chk_enabled "${READSB_FORWARD_MLAT}"; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "WARNING -- READSB_FORWARD_MLAT has been set! Do not feed the output of this container to any aggregators!" + s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING -- READSB_FORWARD_MLAT has been set! Do not feed the output of this container to any aggregators!" READSB_CMD+=("--forward-mlat") fi if chk_enabled "${READSB_FORWARD_MLAT_SBS}"; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "WARNING -- READSB_FORWARD_MLAT_SBS has been set! Do not feed the SBS (BaseStation) output of this container to any aggregators!" + s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING -- READSB_FORWARD_MLAT_SBS has been set! Do not feed the SBS (BaseStation) output of this container to any aggregators!" READSB_CMD+=("--forward-mlat-sbs") fi @@ -322,14 +322,14 @@ fi # shellcheck disable=SC2086,SC2069 if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS 2>&1 + s6wrap --prepend="${APPNAME}" --timestamps --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS 2>&1 elif [[ "${LOGLEVEL,,}" == "error" ]]; then - s6wrap --quiet --prepend="${APPNAME}" --timestamps --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS 2>&1 1>/dev/null + s6wrap --prepend="${APPNAME}" --timestamps --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS 2>&1 1>/dev/null elif [[ "${LOGLEVEL,,}" == "none" ]]; then "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS >/dev/null 2>/dev/null fi -s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "WARNING: The main readsb instance has exited. Restarting in 10 seconds." +s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING: The main readsb instance has exited. Restarting in 10 seconds." sleep 10 From 75ee01538177749455e213a7f3645095165dfde5 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Fri, 5 May 2023 10:16:32 +0200 Subject: [PATCH 2/3] improve s6wrap usage, make sure service stop is respected alias can only be used in interactive shell scripts, replace with bash array var --- .../cont-init.d/01-print-container-version | 4 +- rootfs/etc/cont-init.d/50-store-uuid | 2 +- rootfs/etc/services.d/mlat-client/run | 96 ++++++++++--------- rootfs/etc/services.d/mlathub/run | 23 +++-- rootfs/etc/services.d/prometheus-readsb/run | 6 +- rootfs/etc/services.d/readsb/run | 16 ++-- 6 files changed, 75 insertions(+), 72 deletions(-) diff --git a/rootfs/etc/cont-init.d/01-print-container-version b/rootfs/etc/cont-init.d/01-print-container-version index 2301490..ecc8742 100644 --- a/rootfs/etc/cont-init.d/01-print-container-version +++ b/rootfs/etc/cont-init.d/01-print-container-version @@ -20,6 +20,4 @@ source /scripts/common # If not, see . #--------------------------------------------------------------------------------------------- -alias s6wrap='s6wrap --quiet' - -[[ -f /.CONTAINER_VERSION ]] && s6wrap --prepend=01-print-container-version --timestamps --args echo "Container Version: $(cat /.CONTAINER_VERSION), build date $(stat -c '%y' /.CONTAINER_VERSION |sed 's|\(.*\)\.[0-9]* \(.*\)|\1 \2|g')" || true +[[ -f /.CONTAINER_VERSION ]] && s6wrap --quiet --prepend=01-print-container-version --timestamps --args echo "Container Version: $(cat /.CONTAINER_VERSION), build date $(stat -c '%y' /.CONTAINER_VERSION |sed 's|\(.*\)\.[0-9]* \(.*\)|\1 \2|g')" || true diff --git a/rootfs/etc/cont-init.d/50-store-uuid b/rootfs/etc/cont-init.d/50-store-uuid index d882118..b1759e6 100644 --- a/rootfs/etc/cont-init.d/50-store-uuid +++ b/rootfs/etc/cont-init.d/50-store-uuid @@ -25,4 +25,4 @@ then echo "$UUID" > /run/uuid fi -exit 0 \ No newline at end of file +exit 0 diff --git a/rootfs/etc/services.d/mlat-client/run b/rootfs/etc/services.d/mlat-client/run index 424cee8..92b52fd 100644 --- a/rootfs/etc/services.d/mlat-client/run +++ b/rootfs/etc/services.d/mlat-client/run @@ -17,10 +17,12 @@ # If not, see . #--------------------------------------------------------------------------------------------- -APPNAME="mlat-client" -alias s6wrap='s6wrap --quiet' +trap "pkill -P $$ || true; s6wrap --quiet --timestamps --prepend=mlat-client --args echo 'service stopping'; exit 0" SIGTERM SIGINT SIGHUP SIGQUIT -s6wrap --prepend="${APPNAME}" --timestamps --args echo "Started as an s6 service" +APPNAME="mlat-client" +s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}") + +"${s6wrap[@]}" --args echo "Started as an s6 service" source /scripts/common source /scripts/interpret_ultrafeeder_config @@ -32,28 +34,28 @@ declare -A pid_array if [[ -z "${MLAT_CONFIG}" ]] then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "Warning: MLAT_CONFIG not defined - MLAT will be disabled." - sleep infinity + "${s6wrap[@]}" --args echo "Warning: MLAT_CONFIG not defined - MLAT will be disabled." + exec sleep infinity fi if [[ -z "${MLAT_USER}" ]] && [[ -z "${UUID}" ]] then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "ERROR: either UUID or MLAT_USER must be defined - MLAT will be disabled." - sleep infinity + "${s6wrap[@]}" --args echo "ERROR: either UUID or MLAT_USER must be defined - MLAT will be disabled." + exec sleep infinity fi if [[ -z "$LAT$READSB_LAT" ]]; then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "ERROR: READSB_LAT or LAT must be defined - MLAT will be disabled." - sleep infinity + "${s6wrap[@]}" --args echo "ERROR: READSB_LAT or LAT must be defined - MLAT will be disabled." + exec sleep infinity fi if [[ -z "$LONG$READSB_LON" ]]; then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "ERROR: READSB_LON or LONG must be defined - MLAT will be disabled." - sleep infinity + "${s6wrap[@]}" --args echo "ERROR: READSB_LON or LONG must be defined - MLAT will be disabled." + exec sleep infinity fi if [[ -z "$ALT$READSB_ALT" ]]; then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "ERROR: READSB_ALT or ALT must be defined - MLAT will be disabled." - sleep infinity + "${s6wrap[@]}" --args echo "ERROR: READSB_ALT or ALT must be defined - MLAT will be disabled." + exec sleep infinity fi # MLAT_CONFIG has the following format: @@ -69,6 +71,21 @@ MLAT_CONFIG="${MLAT_CONFIG#"${MLAT_CONFIG%%[![:space:]]*}"}" # strip leading s MLAT_CONFIG="${MLAT_CONFIG//; /;}" readarray -td ";" mlat_configs < <(printf '%s' "${MLAT_CONFIG}") + +# wait until readsb is established... +if ! pgrep readsb >/dev/null; then + if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then + "${s6wrap[@]}" --args echo "Delaying start of MLAT client(s) until container is established..." + fi + while ! pgrep readsb >/dev/null + do + sleep 2 &; wait $! + done + # wait 2 seconds after readsb process exists + sleep 2 &; wait $! +fi + + # Now loop through the MLAT_CONFIG items and start up an Mlat_client for each of them: for instance in "${mlat_configs[@]}" do @@ -79,10 +96,10 @@ do # Check if the params array has values for the mandatory elements: if [[ -z "${params[0]}" ]] || [[ -z "${params[1]}" ]] then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "ERROR -- MLAT_CONFIG is malformed: \"${instance}\". Stopping MLAT execution." + "${s6wrap[@]}" --args echo "ERROR -- MLAT_CONFIG is malformed: \"${instance}\". Stopping MLAT execution." # shellcheck disable=SC2046 kill $(ps -s $$ -o pid=) - sleep infinity + exec sleep infinity fi # Now process the the arguments @@ -92,7 +109,7 @@ do # If the argument isn't any of the above, then it's an "extra argument" unset uuid_arg lat_arg lon_arg alt_arg input_connect_arg return_port_arg extra_args - + for ((i=2; i<${#params[*]}; i++)) do if [[ -n "${params[i]}" ]] && [[ "${params[i]}" =~ ^[0-9]+$ ]]; then @@ -124,6 +141,8 @@ do MLAT_PARAM=(--input-type "${MLAT_INPUT_TYPE:-auto}") MLAT_PARAM+=(--server "${params[0]}:${params[1]}") + servername=${params[0]} + # add return port: [ -n "${return_port_arg}" ] && MLAT_PARAM+=("--results beast,listen,${return_port_arg}") || true @@ -134,7 +153,7 @@ do MLAT_PARAM+=(--user "${MLAT_USER}") else rnd="${RANDOM}" - s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING: MLAT_USER is not set - using random number \"${rnd}\" as MLAT_USER" + "${s6wrap[@]}" --args echo "WARNING: MLAT_USER is not set - using random number \"${rnd}\" as MLAT_USER" MLAT_PARAM+=(--user "${rnd}") fi @@ -169,11 +188,7 @@ do elif [ -n "${UUID}" ]; then MLAT_PARAM+=("--uuid ${UUID}") else - # generate a random UUID - UUID="$(cat /proc/sys/kernel/random/uuid)" - [[ -z "${UUID}" ]] && UUID="$(printf '00000000-ffff-aaaa-%04x-%012x\n' "$RANDOM" "$(date +%s)")" - s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING: UUID is not defined - using randomized uuid \"${UUID}\"" - MLAT_PARAM+=("--uuid ${UUID}") + "${s6wrap[@]}" --args echo "WARNING: UUID is not defined, proceeding without UUID" fi # Now add the extra_args, if any: @@ -184,27 +199,20 @@ do # shellcheck disable=SC2048,SC2086 execstring="$(echo ${MLAT_CMD} ${MLAT_PARAM[*]} | xargs)" + + # stagger by 1 second so they don't all start at the same time + sleep 1 &; wait $! + # ------------------------------------------------ - # Ready to launch, but wait until readsb is established... - if ! pgrep readsb >/dev/null; then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "Delaying start of MLAT client(s) until container is established..." - while ! pgrep readsb >/dev/null - do - sleep 2 - done - fi - sleep 10 # sleep a bit so everything is well established - starting readsb may take a bit - # run this Mlat_client instance in the background: - s6wrap --prepend="${APPNAME}" --timestamps --args echo "starting: ${MLAT_CMD} ${MLAT_PARAM[*]}" - #shellcheck disable=SC2069,SC2086 if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then - { exec s6wrap --prepend="${APPNAME}][${params[0]}" --timestamps --args ${execstring}; } & + "${s6wrap[@]}" --prepend="${APPNAME}][${servername}" --args echo "starting: ${MLAT_CMD} ${MLAT_PARAM[*]}" + "${s6wrap[@]}" --prepend="${APPNAME}][${servername}" --args ${execstring} & elif [[ "${LOGLEVEL,,}" == "error" ]]; then - { exec s6wrap --prepend="${APPNAME}][${params[0]}" --timestamps --args ${execstring} 2>&1 >/dev/null; } & + "${s6wrap[@]}" --ignore-stdout --prepend="${APPNAME}][${servername}" --args ${execstring} & elif [[ "${LOGLEVEL,,}" == "none" ]]; then - { exec ${execstring} >/dev/null 2>/dev/null; } & + "${s6wrap[@]}" --ignore-stderr --ignore-stdout --prepend="${APPNAME}][${servername}" --args ${execstring} & fi # pid_array is indexed by the PID of each mlat_client and contains the MLAT_PARAMs for that instance @@ -212,7 +220,7 @@ do pid_array[$!]="${MLAT_PARAM[*]}" done -sleep 5 +sleep 5 &; wait $! # All MLAT Clients are up, so set the flag. This flag is read by MLATHUB as a sign that it's # safe to start up @@ -226,26 +234,26 @@ do if ! kill -0 "${mlat_pid}" >/dev/null 2>&1 then # it exited - let's restart: - sleep "${RESTARTTIMER}" + sleep "${RESTARTTIMER}" &; wait $! servername="$(awk '{print $4}' <<< "${pid_array[$mlat_pid]}")" servername="${servername%%:*}" - [[ "${LOGLEVEL,,}" != "none" ]] && s6wrap --prepend="${APPNAME}[${servername}" --timestamps --args echo "MLAT_Client ${servername} exited. Attempting to restart." || true + [[ "${LOGLEVEL,,}" != "none" ]] && "${s6wrap[@]}" --prepend="${APPNAME}[${servername}" --args echo "MLAT_Client ${servername} exited. Attempting to restart." || true # shellcheck disable=SC2086 execstring="$(echo ${MLAT_CMD} ${pid_array[$mlat_pid]} | xargs)" #shellcheck disable=SC2069,SC2086 if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then - { exec s6wrap --prepend="${APPNAME}][${servername}" --timestamps --args ${execstring} 2>&1; } & + "${s6wrap[@]}" --prepend="${APPNAME}][${servername}" --args ${execstring} & elif [[ "${LOGLEVEL,,}" == "error" ]]; then - { exec s6wrap --prepend="${APPNAME}][${servername}" --timestamps --args ${execstring} 2>&1 >/dev/null; } & + "${s6wrap[@]}" --ignore-stdout --prepend="${APPNAME}][${servername}" --args ${execstring} & elif [[ "${LOGLEVEL,,}" == "none" ]]; then - { exec ${execstring} >/dev/null 2>/dev/null; } & + "${s6wrap[@]}" --ignore-stderr --ignore-stdout --prepend="${APPNAME}][${servername}" --args ${execstring} & fi pid_array[$!]="${pid_array[${mlat_pid}]}" unset "pid_array[${mlat_pid}]" fi done - sleep 10 + sleep 10 &; wait $! done diff --git a/rootfs/etc/services.d/mlathub/run b/rootfs/etc/services.d/mlathub/run index 7393500..f967cbb 100644 --- a/rootfs/etc/services.d/mlathub/run +++ b/rootfs/etc/services.d/mlathub/run @@ -4,15 +4,15 @@ APPNAME="mlathub" source /scripts/common source /scripts/interpret_ultrafeeder_config -alias s6wrap='s6wrap --quiet' +s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}") if [[ -z "${MLAT_CONFIG}" ]] && [[ -z "$MLATHUB_NET_CONNECTOR" ]]; then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "No MLAT servers have been defined in MLAT_CONFIG and no external sources have been defined in MLATHUB_NET_CONNECTOR - no need to start MLATHUB" + "${s6wrap[@]}" --args echo "No MLAT servers have been defined in MLAT_CONFIG and no external sources have been defined in MLATHUB_NET_CONNECTOR - no need to start MLATHUB" sleep infinity fi if chk_enabled "${MLATHUB_DISABLED}"; then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "MLATHUB is disabled." + "${s6wrap[@]}" --args echo "MLATHUB is disabled." sleep infinity fi @@ -60,7 +60,7 @@ done if (( mlat_result_sources == 0 )) then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "No MLAT servers have been defined in MLAT_CONFIG - no need to start MLATHUB" + "${s6wrap[@]}" --args echo "No MLAT servers have been defined in MLAT_CONFIG - no need to start MLATHUB" sleep infinity fi @@ -110,7 +110,9 @@ MLATHUB_CMD+=("--net-heartbeat=${READSB_NET_HEARTBEAT:-35}") if [[ ! -f /run/mlathub_up ]] then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "Delaying MLAT hub start until container is established..." + if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then + "${s6wrap[@]}" --args echo "Delaying MLAT hub start until container is established..." + fi while [[ ! -f /run/mlathub_up ]] do sleep 2 @@ -118,16 +120,13 @@ then fi sleep 5 # sleep a bit so everything is well established -s6wrap --prepend="${APPNAME}" --timestamps --args echo "Starting MLATHUB..." +"${s6wrap[@]}" --args echo "Starting MLATHUB..." # shellcheck disable=SC2086,SC2069 if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then - s6wrap --prepend="${APPNAME}" --timestamps --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS 2>&1 + exec "${s6wrap[@]}" --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS elif [[ "${LOGLEVEL,,}" == "error" ]]; then - s6wrap --prepend="${APPNAME}" --timestamps --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS 2>&1 >/dev/null + exec "${s6wrap[@]}" --ignore-stdout --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS elif [[ "${LOGLEVEL,,}" == "none" ]]; then - s6wrap --prepend="${APPNAME}" --timestamps --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS >/dev/null 2>/dev/null + exec "${s6wrap[@]}" --ignore-stdtout --ignore-stderr --args "${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS fi - -s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING: The mlathub instance has exited. Restarting in 10 seconds." -sleep 10 diff --git a/rootfs/etc/services.d/prometheus-readsb/run b/rootfs/etc/services.d/prometheus-readsb/run index 30fdc95..7f372ff 100644 --- a/rootfs/etc/services.d/prometheus-readsb/run +++ b/rootfs/etc/services.d/prometheus-readsb/run @@ -8,7 +8,9 @@ if chk_enabled "$PROMETHEUS_ENABLE"; then do sleep 1 done - echo -e "HTTP/1.1 200 OK\nContent-Type: text/plain\n\n$(cat /run/readsb-prometheus.prom)" | ncat -l 9274 > /dev/null 2>&1 + trap "pkill -P $$ || true; s6wrap --timestamps --prepend=prometheus-readsb --quiet --args echo 'service stopping'; exit 0" SIGTERM SIGINT SIGHUP SIGQUIT + echo -e "HTTP/1.1 200 OK\nContent-Type: text/plain\n\n$(cat /run/readsb-prometheus.prom)" | ncat -l 9274 > /dev/null 2>&1 & + wait else - sleep infinity + exec sleep infinity fi diff --git a/rootfs/etc/services.d/readsb/run b/rootfs/etc/services.d/readsb/run index 7c00eb0..971ab1b 100644 --- a/rootfs/etc/services.d/readsb/run +++ b/rootfs/etc/services.d/readsb/run @@ -5,7 +5,7 @@ APPNAME="readsb" source /scripts/common source /scripts/interpret_ultrafeeder_config -alias s6wrap='s6wrap --quiet' +s6wrap=(s6wrap --quiet --timestamps --prepend="${APPNAME}") mkdir -p /run/readsb @@ -65,12 +65,12 @@ if ! chk_enabled "$READSB_NET_SBS_DISABLE_REDUCE"; then fi if chk_enabled "${READSB_FORWARD_MLAT}"; then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING -- READSB_FORWARD_MLAT has been set! Do not feed the output of this container to any aggregators!" + "${s6wrap[@]}" --quiet --args echo "WARNING -- READSB_FORWARD_MLAT has been set! Do not feed the output of this container to any aggregators!" READSB_CMD+=("--forward-mlat") fi if chk_enabled "${READSB_FORWARD_MLAT_SBS}"; then - s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING -- READSB_FORWARD_MLAT_SBS has been set! Do not feed the SBS (BaseStation) output of this container to any aggregators!" + "${s6wrap[@]}" --quiet --args echo "WARNING -- READSB_FORWARD_MLAT_SBS has been set! Do not feed the SBS (BaseStation) output of this container to any aggregators!" READSB_CMD+=("--forward-mlat-sbs") fi @@ -322,14 +322,10 @@ fi # shellcheck disable=SC2086,SC2069 if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then - s6wrap --prepend="${APPNAME}" --timestamps --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS 2>&1 + exec "${s6wrap[@]}" --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS elif [[ "${LOGLEVEL,,}" == "error" ]]; then - s6wrap --prepend="${APPNAME}" --timestamps --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS 2>&1 1>/dev/null + exec "${s6wrap[@]}" --quiet --ignore-stdout --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS elif [[ "${LOGLEVEL,,}" == "none" ]]; then - "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS >/dev/null 2>/dev/null + exec "${s6wrap[@]}" --quiet --ignore-stdout --ignore-stderr --args "${READSB_BIN}" "${READSB_CMD[@]}" $READSB_EXTRA_ARGS fi -s6wrap --prepend="${APPNAME}" --timestamps --args echo "WARNING: The main readsb instance has exited. Restarting in 10 seconds." -sleep 10 - - From 586e9e1296d69358928a0fc8a15fd3b57412191d Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Fri, 5 May 2023 15:26:21 +0200 Subject: [PATCH 3/3] fix syntax error --- rootfs/etc/services.d/mlat-client/run | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rootfs/etc/services.d/mlat-client/run b/rootfs/etc/services.d/mlat-client/run index 92b52fd..8309710 100644 --- a/rootfs/etc/services.d/mlat-client/run +++ b/rootfs/etc/services.d/mlat-client/run @@ -79,10 +79,10 @@ if ! pgrep readsb >/dev/null; then fi while ! pgrep readsb >/dev/null do - sleep 2 &; wait $! + sleep 2 & wait $! done # wait 2 seconds after readsb process exists - sleep 2 &; wait $! + sleep 2 & wait $! fi @@ -201,7 +201,7 @@ do # stagger by 1 second so they don't all start at the same time - sleep 1 &; wait $! + sleep 1 & wait $! # ------------------------------------------------ # run this Mlat_client instance in the background: @@ -220,7 +220,7 @@ do pid_array[$!]="${MLAT_PARAM[*]}" done -sleep 5 &; wait $! +sleep 5 & wait $! # All MLAT Clients are up, so set the flag. This flag is read by MLATHUB as a sign that it's # safe to start up @@ -234,7 +234,7 @@ do if ! kill -0 "${mlat_pid}" >/dev/null 2>&1 then # it exited - let's restart: - sleep "${RESTARTTIMER}" &; wait $! + sleep "${RESTARTTIMER}" & wait $! servername="$(awk '{print $4}' <<< "${pid_array[$mlat_pid]}")" servername="${servername%%:*}" @@ -255,5 +255,5 @@ do unset "pid_array[${mlat_pid}]" fi done - sleep 10 &; wait $! + sleep 10 & wait $! done