xiaowei-system/scripts/startup.sh

35 lines
1.0 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 小唯开机自启动脚本
# 确保DNS容错、关键服务、Feishu连接在开机后自动恢复
set -e
LOG="~/.hermes/logs/startup.log"
mkdir -p ~/.hermes/logs
log() { echo "[$(date '+%m-%d %H:%M')] $*" | tee -a "$LOG"; }
log "=== 小唯开机启动 ==="
# 1. DNS多路容错Cloudflare兜底防止阿里DNS单点故障导致飞书中断
WIFI_DNS=$(nmcli -t -f IP4.DNS device show wlp0s20f3 2>/dev/null | head -1)
if echo "$WIFI_DNS" | grep -q "1.1.1.1"; then
log "DNS已有多路: $WIFI_DNS"
else
log "配置DNS容错..."
nmcli device modify wlp0s20f3 +ipv4.dns "1.1.1.1" 2>/dev/null && log "DNS已加Cloudflare" || log "DNS配置失败"
fi
# 2. 验证飞书连通性
python3 -c "
import socket
try:
ip = socket.gethostbyname('open.feishu.cn')
print(f'飞书DNS解析OK: {ip}')
except Exception as e:
print(f'飞书DNS解析失败: {e}')
" >> "$LOG" 2>&1
# 3. Hermes Gateway状态被动等待systemd拉起不主动重启
log "Hermes服务由systemd管理跳过主动拉起"
log "=== 启动完成 ==="