Formatting
This commit is contained in:
@@ -16,7 +16,7 @@ log() {
|
||||
# Handle local emergency error log immediately
|
||||
if [ "$level" = "ERROR" ]; then
|
||||
mkdir -p "$(dirname "$ERROR_LOG")"
|
||||
printf "%s\n" "$log_line" >> "$ERROR_LOG"
|
||||
printf "%s\n" "$log_line" >>"$ERROR_LOG"
|
||||
fi
|
||||
|
||||
# Dispatch to the Central Logging Daemon via MQTT
|
||||
@@ -72,12 +72,14 @@ fi
|
||||
log "INFO" "Waiting for sync confirmation on $RESPONSE_TOPIC..."
|
||||
|
||||
# Start a subshell that kills the subscriber after 10 seconds if no message arrives
|
||||
( sleep 10; mosquitto_pub -h 127.0.0.1 -t "$RESPONSE_TOPIC" -m "SaveSync=timeout" ) &
|
||||
(
|
||||
sleep 10
|
||||
mosquitto_pub -h 127.0.0.1 -t "$RESPONSE_TOPIC" -m "SaveSync=timeout"
|
||||
) &
|
||||
TIMEOUT_PID=$!
|
||||
|
||||
# -C 1 ensures we exit after receiving either the real response or the timeout message
|
||||
mosquitto_sub -h 127.0.0.1 -p 1883 -t "$RESPONSE_TOPIC" -C 1 | while IFS="=" read -r key value
|
||||
do
|
||||
mosquitto_sub -h 127.0.0.1 -p 1883 -t "$RESPONSE_TOPIC" -C 1 | while IFS="=" read -r key value; do
|
||||
# Kill the background sleep timer since we got a message
|
||||
kill "$TIMEOUT_PID" 2>/dev/null
|
||||
|
||||
@@ -93,4 +95,3 @@ do
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
@@ -7,12 +7,11 @@ touch "$LOG_FILE"
|
||||
touch "$ERROR_FILE"
|
||||
|
||||
log_to_file() {
|
||||
printf "%s\n" "$1" >> "$LOG_FILE"
|
||||
printf "%s\n" "$1" >>"$LOG_FILE"
|
||||
}
|
||||
|
||||
# Subscribe and wait for log entries
|
||||
mosquitto_sub -h 127.0.0.1 -t "$LOG_TOPIC" | while read -r line
|
||||
do
|
||||
mosquitto_sub -h 127.0.0.1 -t "$LOG_TOPIC" | while read -r line; do
|
||||
# The line will look like: SaveLog=[2026-...] [INFO] ...
|
||||
# We strip the "SaveLog=" prefix
|
||||
msg_content="${line#SaveLog=}"
|
||||
|
||||
@@ -12,7 +12,7 @@ log() {
|
||||
|
||||
if [ "$level" = "ERROR" ]; then
|
||||
mkdir -p "$(dirname "$ERROR_LOG")"
|
||||
printf "%s\n" "$log_line" >> "$ERROR_LOG"
|
||||
printf "%s\n" "$log_line" >>"$ERROR_LOG"
|
||||
fi
|
||||
|
||||
# FIX: Corrected port to 1883 and added -m
|
||||
@@ -25,8 +25,7 @@ sleep 2
|
||||
log "INFO" "--- ES Event Daemon Started ---"
|
||||
|
||||
# --- Main Listener Loop ---
|
||||
mosquitto_sub -h 127.0.0.1 -p 1883 -q 0 -t "$TOPIC" | while IFS="=" read -r key value
|
||||
do
|
||||
mosquitto_sub -h 127.0.0.1 -p 1883 -q 0 -t "$TOPIC" | while IFS="=" read -r key value; do
|
||||
# 1. Clean input
|
||||
value=$(echo "$value" | tr -d '\r')
|
||||
|
||||
@@ -80,7 +79,11 @@ do
|
||||
fi
|
||||
|
||||
# Reset variables immediately so the loop is ready for the next line
|
||||
this_system_id=""; this_game_path=""; this_save_path=""; this_action=""; this_backup_path=""
|
||||
this_system_id=""
|
||||
this_game_path=""
|
||||
this_save_path=""
|
||||
this_action=""
|
||||
this_backup_path=""
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user