-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart
More file actions
executable file
·77 lines (69 loc) · 2.58 KB
/
Copy pathstart
File metadata and controls
executable file
·77 lines (69 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# 奇點世界 — Rust 版一鍵啟動:閘門 → 建置後端 → 建置 Hex 編輯器 → 啟動。
# 用法:./start
# 需已安裝 trunk(cargo install trunk),供 /hex-editor 靜態資源;若無 trunk 會中止並提示。
set -e
cd "$(dirname "$0")"
SW_DIR="$(pwd)"
PORT=1721
DATABASE_URL="${DATABASE_URL:-postgres://postgres:singularity@localhost:5432/singularity}"
# 1) 偵測環境與服務
HAS_SYSTEMD=false
if systemctl --user list-unit-files singularity.service &>/dev/null; then
HAS_SYSTEMD=true
fi
# 2) 嚴格閘門(Rust 版:clippy → test → checkrooms)
echo "--- [1/3] 品質檢查 (Clippy) ---"
cargo clippy -- -D warnings
echo "--- [2/3] 邏輯測試 (Test) ---"
cargo test
echo "--- [3/3] 房間契約 (Checkrooms) ---"
cargo run --bin checkrooms -- -brackets -strict
# 3) 建置奇點(Rust release)
echo "--- 建置執行檔 (Release) ---"
# cargo incremental 有時抓不到 dirty 檔,強制戳 mtime 保險
# 2026-04-20 教訓:handler.rs 明明改了,cargo 判無改動跳過重編,跑的還是舊 binary 的死鎖 bug
if [[ -n "$(git status --porcelain src 2>/dev/null)" ]]; then
find src -name '*.rs' -exec touch {} +
fi
cargo build --release
CARGO_OUT="${CARGO_TARGET_DIR:-target}/release/singularity_world"
if [[ ! -f "$CARGO_OUT" ]]; then
for candidate in "$HOME/target_ram/release/singularity_world" "target/release/singularity_world"; do
if [[ -f "$candidate" ]]; then CARGO_OUT="$candidate"; break; fi
done
fi
mkdir -p bin
install -m 755 "$CARGO_OUT" bin/server-rust
# 4) 重啟服務(兩種路徑都須先釋放 PORT,否則舊的 nohup/殘留行程會讓新實例 bind 失敗)
free_port() {
local pids
pids=$(lsof -ti :"$PORT" 2>/dev/null) || true
if [[ -n "$pids" ]]; then
echo "--- 釋放埠 :$PORT(PID: $pids)---"
kill $pids 2>/dev/null || true
sleep 1
pids=$(lsof -ti :"$PORT" 2>/dev/null) || true
[[ -n "$pids" ]] && kill -9 $pids 2>/dev/null || true
sleep 1
fi
}
if [ "$HAS_SYSTEMD" = true ]; then
echo "--- 透過 systemd 重啟服務 ---"
systemctl --user stop singularity.service 2>/dev/null || true
sleep 1
free_port
systemctl --user set-environment DATABASE_URL="$DATABASE_URL"
systemctl --user start singularity.service
sleep 1
systemctl --user status singularity.service | head -n 5
else
echo "--- 手動重啟 (nohup) ---"
free_port
if [[ -f "$SW_DIR/.env" ]]; then
set -a; source "$SW_DIR/.env"; set +a
fi
nohup env PORT=$PORT DATABASE_URL="$DATABASE_URL" ./bin/server-rust >> sw.log 2>&1 &
sleep 2
echo "已啟動。log:$SW_DIR/sw.log"
fi