- Reorder init(): loadTrades() runs first, charts second - Wrap chart init in try-catch so UI survives CDN issues - Update start.sh to detect changes in embedded .html/.js/.css
57 lines
1.5 KiB
Bash
Executable File
57 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# exchange-monitor 启动脚本
|
|
# 自动检测端口占用并清理旧进程
|
|
|
|
set -e
|
|
|
|
cd "$(dirname "$0")"
|
|
PORT=8888
|
|
BIN="./exchange-monitor"
|
|
LOG="exchange-monitor.log"
|
|
|
|
# 检查端口占用,释放旧进程
|
|
PID=$(ss -tlnp 2>/dev/null | grep ":$PORT " | sed -n 's/.*pid=\([0-9]*\).*/\1/p')
|
|
if [ -n "$PID" ]; then
|
|
echo "[start] Port $PORT 被 PID=$PID 占用,尝试优雅停止..."
|
|
kill "$PID" 2>/dev/null || true
|
|
sleep 1
|
|
# 强制清理
|
|
if kill -0 "$PID" 2>/dev/null; then
|
|
echo "[start] 强制终止 PID=$PID..."
|
|
kill -9 "$PID" 2>/dev/null || true
|
|
sleep 1
|
|
fi
|
|
fi
|
|
|
|
# 确认端口空闲
|
|
if ss -tlnp 2>/dev/null | grep -q ":$PORT "; then
|
|
echo "[start] ERROR: 端口 $PORT 仍被占用,放弃启动"
|
|
exit 1
|
|
fi
|
|
|
|
# 编译(如果源码或嵌入文件有变更)
|
|
WEB_FILES=$(find web/static -name '*.html' -o -name '*.js' -o -name '*.css' 2>/dev/null)
|
|
if [ ! -x "$BIN" ] || [ -n "$(find . -name '*.go' $WEB_FILES -newer "$BIN" 2>/dev/null | head -1)" ]; then
|
|
echo "[start] 编译新二进制..."
|
|
go build -o "$BIN" . 2>&1
|
|
fi
|
|
|
|
# 启动
|
|
echo "[start] 启动 exchange-monitor (端口 $PORT)..."
|
|
nohup "$BIN" >> "$LOG" 2>&1 &
|
|
PID=$!
|
|
echo "[start] PID=$PID"
|
|
|
|
# 等待就绪
|
|
for i in $(seq 1 10); do
|
|
if ss -tlnp 2>/dev/null | grep -q ":$PORT "; then
|
|
echo "[start] 就绪 (${i}s)"
|
|
echo "[start] http://localhost:$PORT"
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
echo "[start] 启动超时(10s),请检查日志: tail -f $LOG"
|
|
exit 1
|