@@ -33,6 +33,20 @@ yum update -y
33
33
yum -y install amazon-cloudwatch-agent collectd jq yq gcc ncurses-devel aws-cfn-bootstrap zstd
34
34
wget $YQ_URI -O /usr/bin/yq && chmod +x /usr/bin/yq
35
35
36
+ # install aria2 a p2p downloader
37
+
38
+ if [ " $arch " == " x86_64" ]; then
39
+ wget https://github.com/q3aql/aria2-static-builds/releases/download/v1.36.0/aria2-1.36.0-linux-gnu-64bit-build1.tar.bz2
40
+ tar jxvf aria2-1.36.0-linux-gnu-64bit-build1.tar.bz2
41
+ cd aria2-1.36.0-linux-gnu-64bit-build1/
42
+ make install
43
+ else
44
+ wget https://github.com/q3aql/aria2-static-builds/releases/download/v1.36.0/aria2-1.36.0-linux-gnu-arm-rbpi-build1.tar.bz2
45
+ tar jxvf aria2-1.36.0-linux-gnu-arm-rbpi-build1.tar.bz2
46
+ cd aria2-1.36.0-linux-gnu-arm-rbpi-build1/
47
+ make install
48
+ fi
49
+
36
50
cd /opt
37
51
38
52
echo " Downloading assets zip file"
@@ -187,6 +201,8 @@ case $NETWORK_ID in
187
201
;;
188
202
esac
189
203
204
+ echo " OP_NODE_L1_TRUST_RPC=true" >> $OP_CONFIG_FILE_PATH
205
+
190
206
sed -i " s#GETH_HOST_DATA_DIR=./geth-data#GETH_HOST_DATA_DIR=/data/geth#g" /home/bcuser/node/.env
191
207
192
208
chown -R bcuser:bcuser /home/bcuser/node
@@ -198,6 +214,27 @@ chmod 766 /opt/syncchecker.sh
198
214
echo " */5 * * * * /opt/syncchecker.sh" | crontab
199
215
crontab -l
200
216
217
+ echo " Configuring node as a service"
218
+ mkdir /home/bcuser/bin
219
+ mv /opt/base/node.sh /home/bcuser/bin/node.sh
220
+ chmod 766 /home/bcuser/bin/node.sh
221
+ chown -R bcuser:bcuser /home/bcuser
222
+
223
+ sudo bash -c ' cat > /etc/systemd/system/base.service <<EOF
224
+ [Unit]
225
+ Description=Base Node
226
+ After=network-online.target
227
+ [Service]
228
+ Type=simple
229
+ Restart=always
230
+ RestartSec=30
231
+ User=bcuser
232
+ Environment="PATH=/bin:/usr/bin:/home/bcuser/bin"
233
+ ExecStart=/home/bcuser/bin/node.sh
234
+ [Install]
235
+ WantedBy=multi-user.target
236
+ EOF'
237
+
201
238
echo " Signaling completion to CloudFormation to continue with volume mount"
202
239
/opt/aws/bin/cfn-signal --stack $STACK_NAME --resource $RESOURCE_ID --region $REGION
203
240
@@ -235,21 +272,21 @@ chown -R bcuser:bcuser /data
235
272
chmod -R 755 /data
236
273
237
274
if [ " $RESTORE_FROM_SNAPSHOT " == " false" ]; then
238
- echo " Skipping restoration from snapshot. Starting docker-compose in 3 min. "
239
- cd /home/bcuser/node
240
- echo " sudo su bcuser && /usr/local/bin/docker-compose -f /home/bcuser/node/docker-compose.yml up -d " | at now +3 minutes
275
+ echo " Skipping restoration from snapshot. Starting node "
276
+ sudo systemctl daemon-reload
277
+ sudo systemctl enable -- now base
241
278
else
242
- echo " Restoring data from snapshot"
243
- chmod 766 /opt/start-from-snapshot.sh
244
- /opt/download-snapshot.sh
245
- if [ " $? " == 0 ]; then
246
- echo " Snapshot download successful"
247
- else
248
- echo " Snapshot download failed, falling back to fresh sync"
249
- fi
250
- chown -R bcuser:bcuser /data
251
- sudo su bcuser
252
- /usr/local/bin/docker-compose -f /home/bcuser/node/docker-compose.yml up -d
279
+ echo " Restoring node from snapshot"
280
+ chmod +x /opt/restore-from-snapshot.sh
281
+ echo " /opt/restore-from-snapshot.sh" | at now + 1 min
282
+ fi
283
+
284
+ if [[ " $LIFECYCLE_HOOK_NAME " != " none" ]]; then
285
+ echo " Signaling ASG lifecycle hook to complete"
286
+ TOKEN=$( curl -s -X PUT " http://169.254.169.254/latest/api/token" -H " X-aws-ec2-metadata-token-ttl-seconds: 21600" )
287
+ INSTANCE_ID=$( curl -H " X-aws-ec2-metadata-token: $TOKEN " -s http://169.254.169.254/latest/meta-data/instance-id)
288
+ aws autoscaling complete-lifecycle-action --lifecycle-action-result CONTINUE --instance-id $INSTANCE_ID --lifecycle-hook-name " $LIFECYCLE_HOOK_NAME " --auto-scaling-group-name " $AUTOSCALING_GROUP_NAME " --region $AWS_REGION
253
289
fi
254
290
255
291
echo " All Done!!"
292
+ set -e
0 commit comments