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