Skip to content

Commit 5f0b09f

Browse files
committed
Base. Added alternative snapshot downloads from S3 URL.
1 parent 7cc335f commit 5f0b09f

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
set +e
3+
4+
source /etc/environment
5+
6+
echo "Downloading Snapshot."
7+
8+
cd /data
9+
10+
SNAPSHOT_FILE_NAME=snapshot.tar.gz
11+
SNAPSHOT_DIR=/data
12+
13+
LATEST_SNAPSHOT_FILE_NAME=$(curl https://$NETWORK_ID-$NODE_CONFIG-snapshots.base.org/latest) && \
14+
s5cmd --log error cp s3://base-snapshots-$NETWORK_ID-archive/$LATEST_SNAPSHOT_FILE_NAME /data && \
15+
echo "Downloading Snapshot script finished" && \
16+
sleep 60 &&\
17+
echo "Starting snapshot decompression ..." && \
18+
tar -zxvf $SNAPSHOT_DIR/$SNAPSHOT_FILE_NAME -C /data 2>&1 | tee unzip.log && echo "decompresed successfully..." || echo "decompression failed..." >> snapshots-decompression.log
19+
20+
echo "Decompresed snapshot, cleaning up..."
21+
22+
mv /data/snapshots/$NETWORK_ID/download/* /data && \
23+
rm -rf /data/snapshots && \
24+
rm -rf $SNAPSHOT_DIR/$SNAPSHOT_FILE_NAME
25+
26+
echo "Snapshot is ready, starting the service.."
27+
28+
chown -R bcuser:bcuser /data
29+
30+
sudo systemctl daemon-reload
31+
sudo systemctl enable --now base

lib/base/lib/assets/restore-from-snapshot.sh renamed to lib/base/lib/assets/restore-from-snapshot-http.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ if [ "$SNAPSHOT_URL" == "none" ] || [ -z "${SNAPSHOT_URL}" ]; then
1616
SNAPSHOT_URL=https://$NETWORK_ID-$NODE_CONFIG-snapshots.base.org/$LATEST_SNAPSHOT_FILE_NAME
1717
fi
1818

19-
# take about 1 hour to download the Snapshot
2019
while (( SNAPSHOT_DOWNLOAD_STATUS != 0 ))
2120
do
2221
PIDS=$(pgrep aria2c)

lib/base/lib/assets/setup-instance-store-volumes.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ if [ -n "$DATA_VOLUME_ID" ]; then
1313

1414
mkfs.ext4 $DATA_VOLUME_ID
1515
echo "Data volume formatted. Mounting..."
16-
# Waiting wihtouht using sleep as it sometimes just hangs....
17-
coproc read -t 10 && wait "$!" || true
16+
echo "waiting for volume to get UUID"
17+
OUTPUT=0;
18+
while [ "$OUTPUT" = 0 ]; do
19+
DATA_VOLUME_UUID=$(lsblk -fn -o UUID $DATA_VOLUME_ID)
20+
OUTPUT=$(echo $DATA_VOLUME_UUID | grep -c - $2)
21+
echo $OUTPUT
22+
done
1823
DATA_VOLUME_UUID=$(lsblk -fn -o UUID $DATA_VOLUME_ID)
1924
DATA_VOLUME_FSTAB_CONF="UUID=$DATA_VOLUME_UUID /data ext4 defaults 0 2"
2025
echo "DATA_VOLUME_ID="$DATA_VOLUME_ID

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ yum update -y
3535
yum -y install amazon-cloudwatch-agent collectd jq yq gcc ncurses-devel aws-cfn-bootstrap zstd
3636
wget $YQ_URI -O /usr/bin/yq && chmod +x /usr/bin/yq
3737

38-
# install aria2 a p2p downloader
38+
echo " Installing aria2 a p2p downloader"
3939
cd /tmp
4040

4141
if [ "$arch" == "x86_64" ]; then
@@ -50,6 +50,14 @@ else
5050
make install
5151
fi
5252

53+
echo " Installing s5cmd"
54+
cd /opt
55+
wget -q $S5CMD_URI -O s5cmd.tar.gz
56+
tar -xf s5cmd.tar.gz
57+
chmod +x s5cmd
58+
mv s5cmd /usr/bin
59+
s5cmd version
60+
5361
cd /opt
5462

5563
echo "Downloading assets zip file"
@@ -83,7 +91,6 @@ yum install -y $SSM_AGENT_BINARY_URI
8391
REGION=${_REGION_}
8492
STACK_NAME=${_STACK_NAME_}
8593
RESTORE_FROM_SNAPSHOT=${_RESTORE_FROM_SNAPSHOT_}
86-
FORMAT_DISK=${_FORMAT_DISK_}
8794
NETWORK_ID=${_NETWORK_ID_}
8895
NODE_CONFIG=${_NODE_CONFIG_}
8996
L1_EXECUTION_ENDPOINT=${_L1_EXECUTION_ENDPOINT_}
@@ -290,9 +297,15 @@ if [ "$RESTORE_FROM_SNAPSHOT" == "false" ]; then
290297
systemctl daemon-reload
291298
systemctl enable --now base
292299
else
293-
echo "Restoring node from snapshot"
294-
chmod +x /opt/restore-from-snapshot.sh
295-
echo "/opt/restore-from-snapshot.sh" | at now + 1 min
300+
if [ "$NODE_CONFIG" == "archive" ]; then
301+
echo "Restoring archive node from snapshot over s3"
302+
chmod +x /opt/restore-from-snapshot-archive-s3.sh
303+
echo "/opt/restore-from-snapshot-archive-s3.sh" | at now + 1 min
304+
else
305+
echo "Restoring full node from snapshot over http"
306+
chmod +x /opt/restore-from-snapshot-http.sh
307+
echo "/opt/restore-from-snapshot-http.sh" | at now + 1 min
308+
fi
296309
fi
297310

298311
if [[ "$LIFECYCLE_HOOK_NAME" != "none" ]]; then
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"base-single-node-archive-mainnet": {
3-
"nodeinstanceid": "i-0206eadc184b36db5"
3+
"nodeinstanceid": "i-03efb8b36f80c2fd1"
44
}
55
}

0 commit comments

Comments
 (0)