This repository was archived by the owner on Jan 16, 2025. It is now read-only.
File tree 1 file changed +35
-4
lines changed
modules/runners/templates
1 file changed +35
-4
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash -e
2
2
3
+ install_with_retry () {
4
+ max_attempts=5
5
+ attempt_count=0
6
+ success=false
7
+ while [ $success = false ] && [ $attempt_count -le $max_attempts ]; do
8
+ echo " Attempting $attempt_count /$max_attempts : Installing $* "
9
+ dnf install -y $*
10
+ if [ $? -eq 0 ]; then
11
+ success=true
12
+ else
13
+ echo " Failed to install $1 - retrying"
14
+ attempt_count=$(( attempt_count + 1 ))
15
+ sleep 5
16
+ fi
17
+ done
18
+ }
19
+
3
20
exec > >( tee /var/log/user-data.log | logger -t user-data -s 2> /dev/console) 2>&1
4
21
5
22
# AWS suggest to create a log for debug purpose based on https://aws.amazon.com/premiumsupport/knowledge-center/ec2-linux-log-user-data/
@@ -15,15 +32,29 @@ set -x
15
32
16
33
${pre_install}
17
34
18
- dnf upgrade-minimal -y
35
+ max_attempts=5
36
+ attempt_count=0
37
+ success=false
38
+ while [ $success = false ] && [ $attempt_count -le $max_attempts ]; do
39
+ echo " Attempting $attempt_count /$max_attempts : upgrade-minimal"
40
+ dnf upgrade-minimal -y
41
+ if [ $? -eq 0 ]; then
42
+ success=true
43
+ else
44
+ echo " Failed to run ` dnf upgrad-minimal -y` - retrying"
45
+ attempt_count=$(( attempt_count + 1 ))
46
+ sleep 5
47
+ fi
48
+ done
19
49
20
50
# Install docker
21
- dnf install -y docker
51
+ install_with_retry docker
52
+
22
53
service docker start
23
54
usermod -a -G docker ec2-user
24
55
25
- dnf install -y amazon-cloudwatch-agent jq git
26
- dnf install -y --allowerasing curl
56
+ install_with_retry amazon-cloudwatch-agent jq git
57
+ install_with_retry --allowerasing curl
27
58
28
59
user_name=ec2-user
29
60
You can’t perform that action at this time.
0 commit comments