Skip to content

Commit 78e7030

Browse files
committed
Merging changes with yinal code
1 parent 7f74e64 commit 78e7030

File tree

1 file changed

+87
-32
lines changed
  • lib/sui/lib/assets/user-data

1 file changed

+87
-32
lines changed

lib/sui/lib/assets/user-data/node.sh

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
22

3+
# via https://github.com/Contribution-DAO/sui-node-setup
4+
# Modifications made by yinalaws in 2024
5+
# ASCII art removed for brevity, silenced interactions, added testnet p2p, Ubuntu 24.04 LTS tests
6+
37
echo "[LOG] script start"
48

59
set +e
@@ -9,14 +13,13 @@ set +e
913
echo "STACK_NAME=${_STACK_NAME_}"
1014
echo "STACK_ID=${_STACK_ID_}"
1115
echo "RESOURCE_ID=${_NODE_CF_LOGICAL_ID_}"
12-
16+
echo "ASSETS_S3_PATH=${_ASSETS_S3_PATH_}"
1317
echo "DATA_VOLUME_TYPE=${_DATA_VOLUME_TYPE_}"
1418
echo "DATA_VOLUME_SIZE=${_DATA_VOLUME_SIZE_}"
1519
echo "NETWORK_ID=${_NETWORK_ID_}"
1620

1721
echo "HOME=/home/ubuntu"
1822
} >> /etc/environment
19-
2023
source /etc/environment
2124

2225
# Validate the release channel
@@ -29,17 +32,15 @@ case $NETWORK_ID in
2932
;;
3033
esac
3134

32-
# via https://github.com/Contribution-DAO/sui-node-setup
33-
# Modifications made by yinalaws in 2024
34-
# ASCII art removed for brevity, silenced interactions, added testnet p2p, Ubuntu 24.04 LTS tests
3535

36-
# 1. Updating packages
36+
# Updating packages
3737
echo "[LOG] updating packages"
38+
export DEBIAN_FRONTEND=noninteractive
3839
sudo apt-get -qq update && sudo apt upgrade -y
3940
sudo apt-get -qq install -y build-essential
40-
sudo apt-get -qq install -y libclang-dev
41-
sudo apt-get -qq install -y pkg-config libssl-dev
42-
sudo apt-get install -y libpq-dev # dependency of sui-tool
41+
sudo apt-get -qq install -y libclang-dev pkg-config libssl-dev
42+
sudo apt-get -qq install -y awscli jq unzip
43+
sudo apt-get -qq install -y libpq-dev # dependency of sui-tool
4344

4445
# emitting cfn-signal event
4546
sudo apt-get -qq install -y python3-pip
@@ -63,22 +64,83 @@ if [[ ":$PATH:" != *":/usr/bin:"* ]]; then
6364
echo 'export PATH=$PATH:/usr/bin' >> ~/.bashrc
6465
source ~/.bashrc
6566
fi
66-
67-
# 2. Install dependencies
67+
# Install dependencies
6868
echo "[LOG] Install dependencies"
69+
sudo apt-get -qq install -y --no-install-recommends tzdata git ca-certificates curl cmake
70+
sudo apt-get -qq install -y libprotobuf-dev protobuf-compiler
6971

70-
sudo apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y --no-install-recommends tzdata git ca-certificates curl cmake jq
71-
sudo apt install -y libprotobuf-dev protobuf-compiler
7272

73-
# 3. Install Rust
74-
# echo "[LOG] install rust"
75-
# sudo curl https://sh.rustup.rs -sSf | sh -s -- -y
76-
# source $HOME/.cargo/env
73+
#### Mounting volume ####
7774

78-
# 4. Download Sui artifacts
79-
cd $HOME
75+
echo "Waiting for volumes to be available"
76+
sleep 60
8077

81-
# Executing function that downloads official binaries from github
78+
# Define base mount point directory
79+
MOUNT_POINT_BASE="/suidisk"
80+
81+
# Create the base mount point directory if it doesn't exist
82+
if [ ! -d "$MOUNT_POINT_BASE" ]; then
83+
echo "Creating mount point $MOUNT_POINT_BASE"
84+
sudo mkdir -p "$MOUNT_POINT_BASE"
85+
fi
86+
87+
# Specify the volume name
88+
volume="/dev/nvme1n1"
89+
90+
# Create an ext4 filesystem on the volume
91+
echo "Creating ext4 filesystem on $volume"
92+
sudo mkfs -t ext4 -F $volume
93+
94+
# Get the UUID of the volume
95+
UUID=$(sudo blkid -s UUID -o value $volume)
96+
97+
# Add the volume to /etc/fstab if it's not already there
98+
if ! grep -q "$UUID" /etc/fstab; then
99+
echo "Adding $volume to /etc/fstab"
100+
echo "UUID=$UUID $MOUNT_POINT_BASE ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab
101+
else
102+
echo "Volume $volume is already in /etc/fstab"
103+
fi
104+
105+
# Mount the volume to the base mount point
106+
echo "Mounting $volume to $MOUNT_POINT_BASE"
107+
sudo mount $volume $MOUNT_POINT_BASE
108+
109+
# Change ownership to the 'ubuntu' user
110+
echo "Changing ownership of $MOUNT_POINT_BASE to ubuntu:ubuntu"
111+
sudo chown ubuntu:ubuntu -R $MOUNT_POINT_BASE
112+
113+
# Switch to the large disk
114+
cd $MOUNT_POINT_BASE
115+
116+
echo "Volume $volume is mounted and ready to use at $MOUNT_POINT_BASE"
117+
118+
#### End of mounting EBS ####
119+
120+
121+
# Download Assets
122+
cd /opt #
123+
echo "Downloading assets zip file"
124+
aws s3 cp $ASSETS_S3_PATH ./assets.zip
125+
unzip -q assets.zip
126+
127+
echo "Install and configure CloudWatch agent"
128+
wget -q https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
129+
dpkg -i -E amazon-cloudwatch-agent.deb
130+
131+
echo 'Configuring CloudWatch Agent'
132+
mkdir -p /opt/aws/amazon-cloudwatch-agent/etc/
133+
cp /opt/cw-agent.json /opt/aws/amazon-cloudwatch-agent/etc/custom-amazon-cloudwatch-agent.json # TODO: TEST AGAIN - copy from assets
134+
135+
echo "Starting CloudWatch Agent"
136+
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
137+
-a fetch-config -c file:/opt/aws/amazon-cloudwatch-agent/etc/custom-amazon-cloudwatch-agent.json -m ec2 -s
138+
systemctl status amazon-cloudwatch-agent
139+
140+
141+
142+
# Download Sui artifacts
143+
cd $HOME
82144

83145
download_sui_binaries() {
84146
echo "Fetching tags for ${!NETWORK_ID}..."
@@ -132,12 +194,13 @@ download_sui_binaries() {
132194

133195
}
134196

197+
# Executing function that downloads official binaries from github
135198
download_sui_binaries
136199
sudo cp ./sui-node /usr/local/bin/
137200
sudo cp ./sui /usr/local/bin/
138201
sudo cp ./sui-tool /usr/local/bin/
139202

140-
# 5. Update Configs
203+
# Update Configs
141204
echo "[LOG] update configs"
142205
mkdir -p $HOME/.sui/
143206
cd $HOME/.sui/
@@ -150,9 +213,10 @@ sed -i 's/127.0.0.1/0.0.0.0/' $HOME/.sui/fullnode.yaml
150213
sed -i "s|db-path:.*|db-path: $HOME/.sui/db|g" $HOME/.sui/fullnode.yaml
151214
sed -i "s|genesis-file-location:.*|genesis-file-location: $HOME/.sui/genesis.blob|g" $HOME/.sui/fullnode.yaml
152215

153-
# Testnet p2p peers
216+
# Define the path to the configuration file
154217
echo "[LOG] Adding p2p peers to corresponding release channel"
155218

219+
# Check the value of _NETWORK_ID_ and append the appropriate P2P configuration
156220
case "$NETWORK_ID" in
157221
"mainnet")
158222
echo "Adding mainnet peer configuration"
@@ -208,14 +272,7 @@ EOF
208272
;;
209273
esac
210274

211-
212-
# Mainnet peer configuration
213-
214-
215-
# Devnet peer configuration
216-
# Don't need to configure peers for devnet
217-
218-
# 6. Make Sui Service
275+
# Make Sui Service
219276
echo "[LOG] make Sui service"
220277

221278
sudo tee /etc/systemd/system/suid.service > /dev/null <<EOF
@@ -254,8 +311,6 @@ echo "[LOG] Sui Version: $(sui -V)"
254311

255312
echo "Sui Version: $(sui -V)"
256313

257-
258-
259314
# Useful commands (added as comments)
260315
# Check your node logs: journalctl -fu suid -o cat
261316
# Check your node status: sudo service suid status

0 commit comments

Comments
 (0)