Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions docker/mqtt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,22 @@ while true; do
# sleep first to avoid publishing zeroes on first iteration
sleep "$MQTT_PAUSE"

# output a single line to mosquitto_pub
(/app/orb summary || echo '{}') | jq -c .
# output a single line to mosquitto_pub. orb summary prints a startup
# banner to stderr on every invocation, which would flood the journal at
# MQTT_PAUSE cadence -- so capture stderr in a variable (fd 3 carries the
# real stdout out of the command substitution) and only replay it when
# orb fails (it's the only diagnostic we have then) or mqtt_debug is on.
{
ORB_ERRS=$(/app/orb summary 2>&1 >&3)
ORB_RC=$?
if [ "$ORB_RC" -ne 0 ]; then
echo "orb summary failed (exit $ORB_RC):" >&2
[ -n "$ORB_ERRS" ] && printf '%s\n' "$ORB_ERRS" >&2
echo '{}'
elif [ "$DEBUG_MODE" = "true" ] && [ -n "$ORB_ERRS" ]; then
printf '%s\n' "$ORB_ERRS" >&2
fi
} 3>&1 | jq -c .

done | mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
-t "$STATE_TOPIC" -l -r -k $((MQTT_PAUSE * 2))
Expand Down