#!/bin/bash # 重启验证:开机到公网可用要多久 # # 背景:用户撞上的 1033 是设备**掉电重启**造成的。 # 修之前 systemd-analyze 显示用户空间花了 2 分 6 秒, # 因为 systemd-networkd-wait-online 等一个不归它管的网络, # 干等 2 分钟超时失败,把 network-online.target 一起拖住。 # 已经把它 mask 掉了。 # # 这个脚本:记录重启前的状态 -> 重启 -> 从外面轮询公网 -> # 记录它多久恢复。 set -u MARK=/root/reboot_test_mark.txt echo " 当前开机时长: $(uptime -p)" echo " 当前时间: $(date '+%H:%M:%S')" echo " 服务状态:" for svc in lanremote-relay lanremote-tunnel lanremote-nettune; do printf " %-22s %s\n" "$svc" "$(systemctl is-active $svc)" done echo " 隧道连接: $(curl -s --max-time 5 http://127.0.0.1:20241/metrics 2>/dev/null | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}')" echo " 公网: HTTP $(curl -s -o /dev/null -w '%{http_code}' --max-time 15 -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/v1/health)" date +%s > "$MARK" echo echo " 重启前的时间戳已写入 $MARK: $(cat $MARK)" echo " **现在重启** —— 大概 1 分钟内会断开" sleep 2 reboot