Repository navigation
Expand file tree
/
Copy pathstart_lan_node.sh
More file actions
executable file
·76 lines (63 loc) · 2.38 KB
/
Copy pathstart_lan_node.sh
File metadata and controls
executable file
·76 lines (63 loc) · 2.38 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
#!/bin/bash
# start_lan_node.sh — Launch a single auction node for LAN deployment.
# Usage: chmod +x start_lan_node.sh && ./start_lan_node.sh
# Exit on error
set -e
# Get the directory of the script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# ── CONFIG: change MyNodeId per laptop ──────────────────────────────────
MyNodeId=${1:-1} # <-- Passed as argument, or default to 1
# Remove the old hardcoded line
declare -A LanIPs
LanIPs[1]='10.12.234.8'
LanIPs[2]='10.12.228.13'
LanIPs[3]='10.12.226.20'
LanIPs[4]='10.12.227.210'
Port=$((8000 + MyNodeId)) # Node1→8001, Node2→8002, etc.
# ─────────────────────────────────────────────────────────────────────────
echo "============================================"
echo " Distributed Auction System - LAN Mode"
myIP=${LanIPs[$MyNodeId]}
echo " This laptop: Node$MyNodeId ($myIP:$Port)"
echo "============================================"
# [1] Stop old processes
echo -e "\n[1/4] Stopping old auction_node processes..."
# Find processes named auction_node that are running from this directory
# We look for the executable in the current directory specifically to match PS1 logic
pgrep -f "$(pwd)/auction_node" | xargs -r kill -9 || true
sleep 0.8
# [2] Preserve previous log
echo "[2/4] Preserving previous log..."
log="node${MyNodeId}.log"
lastLog="node${MyNodeId}.last.log"
if [ -f "$log" ]; then
cp "$log" "$lastLog"
fi
# [3] Rebuild
echo "[3/4] Rebuilding auction_node..."
exePath="./auction_node"
if [ -f "$exePath" ]; then
rm "$exePath"
fi
go build -o auction_node .
# [4] Build peer list (all nodes except self)
peers=()
for id in {1..4}; do
if [ "$id" -ne "$MyNodeId" ]; then
peerPort=$((8000 + id))
peers+=("${LanIPs[$id]}:$peerPort")
fi
done
# Join peers with comma
peerList=$(IFS=,; echo "${peers[*]}")
echo "[4/4] Starting Node$MyNodeId on 0.0.0.0:$Port"
echo " Peers: $peerList"
echo " UI: http://localhost:$Port"
echo " LAN: http://$myIP:$Port"
echo ""
echo "Press Ctrl+C to stop."
echo "--------------------------------------------"
# Run in foreground
nodeId="Node$MyNodeId"
$exePath --id "$nodeId" --host 0.0.0.0 --port "$Port" --peers "$peerList"