Skip to content

Commit

Permalink
stop unneeded s6 services instead of exec sleep inf
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Aug 5, 2024
1 parent 8c4e795 commit 7ed551f
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ RUN \
KEPT_PACKAGES+=(libncurses6) && \
# healthchecks
KEPT_PACKAGES+=(jq) && \
# add new function to /scripts/common until it's added to the baseimage
cat < /app/stop_parent_service.func >> /scripts/common && \
# install packages
apt-get update && \
apt-get install -y --no-install-suggests --no-install-recommends \
Expand Down
4 changes: 2 additions & 2 deletions rootfs/etc/s6-overlay/scripts/autogain
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ READSB_AUTOGAIN_INITIAL_TIMEPERIOD="${READSB_AUTOGAIN_INITIAL_TIMEPERIOD:-7200}"

if [[ "${READSB_GAIN,,}" != "autogain" ]]; then
# Autogain is not enabled, so let's do nothing forever
exec sleep infinity
stop_parent_service
fi

if [[ "${READSB_DEVICE_TYPE,,}" != "rtlsdr" ]]; then
s6wrap --quiet --prepend=autogain --timestamps --args echo "ERROR: AUTOGAIN enabled but READSB_DEVICE_TYPE is not \"rtlsdr\". Autogain disabled."
exec sleep infinity
stop_parent_service
fi

mkdir -p /var/globe_history/autogain
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/cleanup_globe_history
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ source /scripts/common

if [[ -z "$MAX_GLOBE_HISTORY" ]]; then
"${s6wrap[@]}" echo "MAX_GLOBE_HISTORY not set - we will not expire any globe_history files"
exec sleep infinity
stop_parent_service
fi

cutoffepoch="$(date -d"-${MAX_GLOBE_HISTORY} days" +%s)"
Expand Down
4 changes: 2 additions & 2 deletions rootfs/etc/s6-overlay/scripts/collectd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mkdir -p /run/collectd


if chk_enabled "${GRAPHS1090_DISABLE}" || chk_enabled "${TAR1090_DISABLE}"; then
exec sleep infinity
stop_parent_service
fi


Expand All @@ -17,7 +17,7 @@ if chk_enabled "${GRAPHS1090_REDUCE_IO}"; then
# readback rrd database from compressed archive
if ! s6wrap --quiet --prepend=graphs1090-readback --timestamps --args bash /usr/share/graphs1090/readback.sh; then
s6wrap --quiet --prepend=graphs1090-readback --timestamps --args echo "FATAL: readback returned an error"
exec sleep infinity
stop_parent_service
fi
elif [[ -f "${PERMFILE}" ]] && ! [[ -d /var/lib/collectd/rrd/localhost ]]; then
# extract rrd database from compressed archive (in case WAS enabled)
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/graphs1090
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source /scripts/common


if chk_enabled "${GRAPHS1090_DISABLE}" || chk_enabled "${TAR1090_DISABLE}"; then
exec sleep infinity
stop_parent_service
fi

mkdir -p /run/graphs1090
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/graphs1090-writeback
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source /scripts/common
trap 'pkill -P $$ || true; exit 0' SIGTERM SIGINT SIGHUP SIGQUIT

if chk_enabled "${GRAPHS1090_DISABLE}" || ! chk_enabled "${GRAPHS1090_REDUCE_IO}" || chk_enabled "${TAR1090_DISABLE}"; then
exec sleep infinity
stop_parent_service
fi

sleep "${GRAPHS1090_REDUCE_IO_FLUSH_IVAL:-1d}" & wait $!
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/nginx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
source /scripts/common

if [[ "$(find /etc/nginx/sites-enabled/ -type f | wc -l)" == "0" ]]; then
exec sleep infinity
stop_parent_service
fi


Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/tar1090
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
source /scripts/common

if chk_enabled "${TAR1090_DISABLE}"; then
exec sleep infinity
stop_parent_service
fi

mkdir -p /run/tar1090
Expand Down
4 changes: 2 additions & 2 deletions rootfs/etc/s6-overlay/scripts/telegraf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap 'pkill -P $$ || true; exit 0' SIGTERM SIGINT SIGHUP SIGQUIT
if [[ -n "$INFLUXDBV2_URL" ]] || chk_enabled "${PROMETHEUS_ENABLE}"; then
if [[ ! -f /usr/bin/telegraf ]]; then
s6wrap --quiet --prepend=telegraf --timestamps --args echo "WARNING: InfluxDB/Prometheus parameters are set but Telegraf not included in this container"
exec sleep infinity
stop_parent_service
fi
# give other services time to stabilise
sleep 5 & wait $!
Expand All @@ -24,5 +24,5 @@ if [[ -n "$INFLUXDBV2_URL" ]] || chk_enabled "${PROMETHEUS_ENABLE}"; then
s6wrap --quiet --prepend=telegraf --timestamps --args telegraf --config-directory /etc/telegraf/telegraf.d | grep -v "error converting to float"
else
# if telegraf not needed, sleep forever
exec sleep infinity
stop_parent_service
fi
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/timelapse1090
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ if chk_enabled "$ENABLE_TIMELAPSE1090" && ! chk_enabled "${TAR1090_DISABLE}"; th

sleep 30 & wait $!
else
exec sleep infinity
stop_parent_service
fi
9 changes: 9 additions & 0 deletions stop_parent_service.func
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

function stop_parent_service() {
_SERVICE=$(ps -q$(ps -cp $$ -o ppid="") -o args= | grep -F s6-supervise | cut -d' ' -f2)
s6-svc -d /run/service/"${_SERVICE}"
# just in case this doesn't work, exec an infinite sleep
# if the service stopping works, the sleep will just be terminated
exec sleep infinity
}

0 comments on commit 7ed551f

Please sign in to comment.