-
Notifications
You must be signed in to change notification settings - Fork 4
/
titan-gcp.sh
114 lines (84 loc) · 3.24 KB
/
titan-gcp.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
echo "--------------------------- Configuration INFO ---------------------------"
echo "CPU: " $(nproc --all) "vCPU"
echo -n "RAM: " && free -h | awk '/Mem/ {sub(/Gi/, " GB", $2); print $2}'
echo "Disk Space" $(df -B 1G --total | awk '/total/ {print $2}' | tail -n 1) "GB"
echo "--------------------------------------------------------------------------"
echo "--------------------------- BASH SHELL TITAN ---------------------------"
# Fixed hash | laodau
hash_value="60CA5D2F-585D-458F-BF73-C297B63BDE9A"
cpu_core=1
memory_size=4
storage_size=120
service_content="
[Unit]
Description=Titan Node
After=network.target
StartLimitIntervalSec=0
[Service]
User=root
ExecStart=/usr/local/titan/titan-edge daemon start
Restart=always
RestartSec=15
[Install]
WantedBy=multi-user.target
"
sudo apt-get update
sudo apt-get install -y nano
VERSION='v0.1.19'
PATCH="89e53b6"
wget https://github.com/Titannet-dao/titan-node/releases/download/${VERSION}/titan-l2edge_${VERSION}_patch_linux_amd64.tar.gz
sudo tar -xf titan-l2edge_${VERSION}_patch_linux_amd64.tar.gz -C /usr/local
sudo mv /usr/local/titan-edge_${VERSION}_${PATCH}_linux_amd64 /usr/local/titan
sudo cp /usr/local/titan/libgoworkerd.so /usr/lib/libgoworkerd.so
rm titan-l2edge_${VERSION}_patch_linux_amd64.tar.gz
# Định nghĩa nội dung cần thêm
content="
export PATH=\$PATH:/usr/local/titan
export LD_LIBRARY_PATH=\$LD_LIZBRARY_PATH:./libgoworkerd.so
"
# Kiểm tra nếu file ~/.bash_profile chưa tồn tại thì tạo mới, nếu đã tồn tại thì ghi thêm
if [ ! -f ~/.bash_profile ]; then
echo "$content" > ~/.bash_profile
source ~/.bash_profile
else
echo "$content" >> ~/.bash_profile
source ~/.bash_profile
fi
echo "Export PATH ~/.bash_profile"
# Chạy titan-edge daemon trong nền
(titan-edge daemon start --init --url https://cassini-locator.titannet.io:5000/rpc/v0 &) &
daemon_pid=$!
echo "PID of titan-edge daemon: $daemon_pid"
# Chờ 10 giây để đảm bảo rằng daemon đã khởi động thành công
sleep 30
# Chạy titan-edge bind trong nền
(titan-edge bind --hash="$hash_value" https://api-test1.container1.titannet.io/api/v2/device/binding &) &
bind_pid=$!
echo "PID of titan-edge bind: $bind_pid"
# Chờ cho quá trình bind kết thúc
wait $bind_pid
sleep 20
# Tiến hành các cài đặt khác
config_file="/root/.titanedge/config.toml"
if [ -f "$config_file" ]; then
sed -i "s/#StorageGB = 2/StorageGB = $storage_size/" "$config_file"
echo "Config StorageGB to: $storage_size GB."
sed -i "s/#MemoryGB = 1/MemoryGB = $memory_size/" "$config_file"
echo "Config MemoryGB to: $memory_size GB."
sed -i "s/#Cores = 1/Cores = $cpu_core/" "$config_file"
echo "Config Cores CPU to: $cpu_core Core."
else
echo "Error: Configuration file $config_file does not exist."
fi
echo "$service_content" | sudo tee /etc/systemd/system/titand.service > /dev/null
# Dừng các tiến trình liên quan đến titan-edge
pkill titan-edge
# Cập nhật systemd
sudo systemctl daemon-reload
# Kích hoạt và khởi động titand.service
sudo systemctl enable titand.service
sudo systemctl start titand.service
sleep 8
# Hiển thị thông tin và cấu hình của titan-edge
sudo systemctl status titand.service && titan-edge config show && titan-edge info