经过测试,发现小米路由器中的tailscale可能会因为某种原因状态异常,
为了让tailscale恢复正常,所以又写了monitor用来监控:
#!/bin/sh# Define Tailscale related paths
TAILSCALED_PATH="/tmp/tailscale/tailscale_1.80.3_arm/tailscaled"
TAILSCALE_PATH="/tmp/tailscale/tailscale_1.80.3_arm/tailscale"
LOG_DIR="/etc/tailscale"
LOG_FILE="$LOG_DIR/tailscale_monitor.log"
LOOP_TIME=600# Create log directory
mkdir -p "$LOG_DIR"# Function: Log messages
log() {echo "$1"echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
}# Function: Check and start Tailscale
start_tailscale() {"$TAILSCALE_PATH" up --advertise-routes=192.168.0.1/24 >> "$LOG_FILE" 2>&1 &if [ $? -eq 0 ]; thenlog "Tailscale started successfully."elselog "Failed to start Tailscale."fi
}# Function: Check and start Tailscaled
start_tailscaled() {if [ -z "$(pgrep -f "$TAILSCALED_PATH")" ]; thenlog "Tailscaled is not running, starting...""$TAILSCALED_PATH" >> "$LOG_FILE" 2>&1 &if [ $? -eq 0 ]; thenlog "Tailscaled started successfully."start_tailscaleelselog "Failed to start Tailscaled."fielselog "Tailscaled is already running."fi
}# Function: Check Tailscale status
check_tailscale_status() {log "Checking Tailscale status..."STATUS=$("$TAILSCALE_PATH" status 2>&1)log "$STATUS"if echo "$STATUS" | grep "xiaomi-ax6000"; thenlog "Device xiaomi-ax6000 found."LINE=$(echo "$STATUS" | grep "xiaomi-ax6000")FOURTH_FIELD=$(echo "$LINE" | awk '{print $5}')if [ "$FOURTH_FIELD" = "offline" ]; thenlog "Device xiaomi-ax6000 is offline, restarting Tailscale..."#pkill -f "$TAILSCALE_PATH"start_tailscaledelserm $LOG_FILElog "Device xiaomi-ax6000 status is normal: $FOURTH_FIELD"fielif echo "$STATUS" | grep "Tailscale is stopped"; thenlog "Tailscale is stopped""$TAILSCALE_PATH" upelselog "Device xiaomi-ax6000 not found."start_tailscalefi
}# Main logic
while true; dolog "Starting Tailscale status check..."start_tailscaled#start_tailscalecheck_tailscale_statuslog "Check completed."log "Waiting for $LOOP_TIME(sec)..."sleep $LOOP_TIME # Sleep for 5 minutes (300 seconds)
done
同时也可以加入到/etc/tailscale/tailscale_install.sh 小米AX6000上安装tailscale
放在最下面
/etc/tailscale/tailscale_monitor.sh &