-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcloud-init.sh
More file actions
executable file
·112 lines (101 loc) · 4.12 KB
/
cloud-init.sh
File metadata and controls
executable file
·112 lines (101 loc) · 4.12 KB
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
#!/bin/bash
source /etc/os-release
if [ $ID == "debian" ] || [ $ID == "ubuntu" ] ; then
default_user=ubuntu
function fix_apt {
apt_process=`ps aux | grep "apt update" | grep -v grep | wc -l`
apt_process=$(( apt_process -1 ))
while [ $apt_process -ge 1 ]
do
echo "wait until apt update is done"
sleep 10s
ps aux | grep "apt update" | grep -v grep
apt_process=`ps aux | grep "apt update" | grep -v grep | wc -l`
apt_process=$(( apt_process -1 ))
done
}
fix_apt
sleep 10s
apt -y --fix-broken install
while true; do
apt update
apt install -y jq
if [ $? -eq 0 ]; then
echo "jq installed"
break
else
echo "jq install failed. Retrying in 10s..."
sleep 10 # Sleep for 10 seconds
fi
done
else
default_user=opc
fi
controller_name=`curl -sH "Authorization: Bearer Oracle" -L http://169.254.169.254/opc/v2/instance/ | jq -r .freeformTags.controller_name`
cluster_name=`curl -sH "Authorization: Bearer Oracle" -L http://169.254.169.254/opc/v2/instance/ | jq -r .freeformTags.cluster_name`
login=`curl -sH "Authorization: Bearer Oracle" -L http://169.254.169.254/opc/v2/instance/ | jq -r .freeformTags.login`
monitoring=`curl -sH "Authorization: Bearer Oracle" -L http://169.254.169.254/opc/v2/instance/ | jq -r .freeformTags.monitoring`
controller=`curl -sH "Authorization: Bearer Oracle" -L http://169.254.169.254/opc/v2/instance/ | jq -r .freeformTags.controller`
hostname_convention=`curl -sH "Authorization: Bearer Oracle" -L http://169.254.169.254/opc/v2/instance/ | jq -r .freeformTags.hostname_convention`
fss=fss-${controller_name}
fss_ip=$(host "${fss}" | awk '{print $4}')
controller_ip=$(host "${controller_name}"| awk '{print $4}')
if [ "$controller" == "true" ] && [ "$controller_name" == `hostname` ]; then
echo "Do not run the cloud-init on the controller, this will create a circular dependency on the /config mount"
exit
fi
mkdir /config
if [ "$fss_ip" == "$controller_ip" ]; then
echo "FSS and controller are on the same host"
if ! grep -qF "$controller_name:/config /config nfs" /etc/fstab; then
echo "$controller_name:/config /config nfs defaults,noatime,bg,timeo=100,ac,actimeo=120,nocto,rsize=1048576,wsize=1048576,nolock,local_lock=all,mountproto=tcp,sec=sys,_netdev 0 0" >> /etc/fstab
systemctl daemon-reload
echo "Entry added to /etc/fstab."
else
echo "Entry already exists in /etc/fstab."
fi
else
if ! grep -qF "$fss:/config /config nfs" /etc/fstab; then
echo "$fss:/config /config nfs defaults,nconnect=16 0 0" >> /etc/fstab
systemctl daemon-reload
echo "Entry added to /etc/fstab."
else
echo "Entry already exists in /etc/fstab."
fi
fi
while true; do
if mountpoint -q /config; then
echo "/config is already mounted. Checking if files are present"
ls /config/bin/compute.sh
if [ $? -eq 0 ]; then
echo "/config/bin/compute.sh is present"
break
else
echo "/config/bin/compute.sh is not present. Retrying in 2 minutes..."
sleep 120 # Sleep for 2 minutes (120 seconds)
fi
fi
echo "Attempting to mount /config"
# Run the mount command and check if it succeeds
mount /config
if [ $? -eq 0 ]; then
ls /config/bin/compute.sh
if [ $? -eq 0 ]; then
echo "Mount succeeded!"
break
else
echo "Mount failed. Retrying in 2 minutes..."
sleep 120 # Sleep for 2 minutes (120 seconds)
fi
else
echo "Mount failed. Retrying in 2 minutes..."
sleep 120 # Sleep for 2 minutes (120 seconds)
fi
done
if [ "$login" == "true" ]; then
su - $default_user /config/bin/login.sh 2>&1 | tee -a /tmp/cloud-init.log
elif [ "$monitoring" == "true" ]; then
su - $default_user /config/bin/monitoring.sh 2>&1 | tee -a /tmp/cloud-init.log
elif [ "$controller" != "true" ] ; then
su - $default_user /config/bin/compute.sh $cluster_name 2>&1 | tee -a /tmp/cloud-init.log
fi