Files
openclaw-backups/scripts/gateway-state-check.sh

26 lines
890 B
Bash

#!/bin/bash
# Gateway State Checker - runs periodically to detect if gateway is down
STATE_FILE="/home/openclaw/.openclaw/gateway-status.state"
LOG_FILE="/home/openclaw/.openclaw/logs/gateway-state.log"
# Check if gateway is running
if systemctl --user is-active --quiet openclaw-gateway.service; then
# Gateway is up
if [ -f "$STATE_FILE" ]; then
if [ "$(cat "$STATE_FILE")" != "up" ]; then
# State changed from down to up, but we'll handle that in the start script
:
fi
fi
# Ensure state is up
echo "up" > "$STATE_FILE"
else
# Gateway is down
if [ ! -f "$STATE_FILE" ] || [ "$(cat "$STATE_FILE")" != "down" ]; then
# First time detecting it's down - update state
echo "down" > "$STATE_FILE"
echo "$(date '+%Y-%m-%d %H:%M:%S') - Gateway is down (state changed to down)" >> "$LOG_FILE"
fi
fi