Skip to content

Commit

Permalink
use process substition + exec instead of pipe (#214)
Browse files Browse the repository at this point in the history
* improve watchdog so it works on unexpected status.json state

* use process substition + exec instead of pipe

exec in bash doesn't work on pipes
but it works with process subsitition so use that and exec

using exec is generally better due to s6-supervise being able to
properly terminate it

eliminate some permanently running bash using exec sleep
  • Loading branch information
wiedehopf authored Nov 20, 2024
1 parent 1d55451 commit 1dfc09a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/piaware
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ if [ "$VERBOSE_LOGGING" = "true" ]; then
fi

# shellcheck disable=SC2016
"${s6wrap[@]}" "${PIAWARE_BIN}" "${PIAWARE_CMD[@]}" | tee -a /var/log/piaware/current
exec "${s6wrap[@]}" "${PIAWARE_BIN}" "${PIAWARE_CMD[@]}" > >(tee -a /var/log/piaware/current)
15 changes: 12 additions & 3 deletions rootfs/etc/s6-overlay/scripts/watchdog
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
source /scripts/common

# checking every 60 seconds
sleep 60
IVAL=60
if [[ $(s6-svdt /run/service/watchdog | wc -l) == 0 ]]; then
# do nothing on first run
exec sleep "$IVAL"
fi

# set this so the || echo 0 works after the pipe
set -eo pipefail

# check if the current date is larger than the expiry field of the status json
if (( $(date +%s) * 1000 > $(grep -o -E -e '(expiry)" *: ([0-9]+)' /run/piaware/status.json | awk '{print $3}') )); then
if (( $(date +%s) * 1000 > "$(grep -o -E -e '(expiry)" *: ([0-9]+)' /run/piaware/status.json | awk '{print $3}' || echo 0)" )); then
# current date being larger means piaware is hanging, kill it
"${s6wrap[@]}" echo "piaware is not updating /run/piaware/status.json, sending SIGKILL"
pkill -9 piaware
"${s6wrap[@]}" pkill -e -9 piaware
fi


Expand All @@ -20,3 +27,5 @@ if (( $(wc -l < /var/log/piaware/current) > 800 )); then
truncate -s 0 /var/log/piaware/current
cat >> /var/log/piaware/current <<< "$keep"
fi

exec sleep "$IVAL"

0 comments on commit 1dfc09a

Please sign in to comment.