|
1 | 1 | echo "$(date -u): running smb script"
|
2 | 2 | weka local ps
|
3 | 3 |
|
4 |
| -# get token for key vault access |
5 |
| -access_token=$(curl 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fvault.azure.net' -H Metadata:true | jq -r '.access_token') |
6 |
| -# get key vault secret |
7 |
| -function_app_key=$(curl "${key_vault_url}secrets/${vault_function_app_key_name}?api-version=2016-10-01" -H "Authorization: Bearer $access_token" | jq -r '.value') |
8 |
| - |
9 |
| -function report { |
10 |
| - local json_data=$1 |
11 |
| - curl ${report_function_url}?code="$function_app_key" -H 'Content-Type:application/json' -d "$json_data" |
12 |
| -} |
13 |
| - |
14 |
| -function wait_for_weka_fs(){ |
15 |
| - filesystem_name="default" |
16 |
| - max_retries=30 # 30 * 10 = 5 minutes |
17 |
| - for (( i=0; i < max_retries; i++ )); do |
18 |
| - if [ "$(weka fs | grep -c $filesystem_name)" -ge 1 ]; then |
19 |
| - echo "$(date -u): weka filesystem $filesystem_name is up" |
20 |
| - break |
21 |
| - fi |
22 |
| - echo "$(date -u): waiting for weka filesystem $filesystem_name to be up" |
23 |
| - sleep 10 |
24 |
| - done |
25 |
| - if (( i > max_retries )); then |
26 |
| - err_msg="timeout: weka filesystem $filesystem_name is not up after $max_retries attempts." |
27 |
| - echo "$(date -u): $err_msg" |
28 |
| - report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"$err_msg\"}" |
29 |
| - return 1 |
30 |
| - fi |
31 |
| -} |
32 |
| - |
33 |
| -function create_config_fs(){ |
34 |
| - filesystem_name=".config_fs" |
35 |
| - size="10GB" |
36 |
| - |
37 |
| - if [ "$(weka fs | grep -c $filesystem_name)" -ge 1 ]; then |
38 |
| - echo "$(date -u): weka filesystem $filesystem_name exists" |
39 |
| - return 0 |
40 |
| - fi |
41 |
| - |
42 |
| - echo "$(date -u): trying to create filesystem $filesystem_name" |
43 |
| - output=$(weka fs create $filesystem_name default $size 2>&1) |
44 |
| - # possiible outputs: |
45 |
| - # FSId: 1 (means success) |
46 |
| - # error: The given filesystem ".config_fs" already exists. |
47 |
| - # error: Not enough available drive capacity for filesystem. requested "10.00 GB", but only "0 B" are free |
48 |
| - if [ $? -eq 0 ]; then |
49 |
| - echo "$(date -u): weka filesystem $filesystem_name is created" |
50 |
| - return 0 |
51 |
| - fi |
52 |
| - |
53 |
| - if [[ $output == *"already exists"* ]]; then |
54 |
| - echo "$(date -u): weka filesystem $filesystem_name already exists" |
55 |
| - break |
56 |
| - elif [[ $output == *"Not enough available drive capacity for filesystem"* ]]; then |
57 |
| - err_msg="Not enough available drive capacity for filesystem $filesystem_name for size $size" |
58 |
| - echo "$(date -u): $err_msg" |
59 |
| - report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"$err_msg\"}" |
60 |
| - return 1 |
61 |
| - else |
62 |
| - echo "$(date -u): output: $output" |
63 |
| - report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"cannot create weka filesystem $filesystem_name\"}" |
64 |
| - return 1 |
65 |
| - fi |
66 |
| -} |
67 |
| - |
68 | 4 | if [[ ${smbw_enabled} == true ]]; then
|
69 | 5 | wait_for_weka_fs || exit 1
|
70 | 6 | create_config_fs || exit 1
|
71 | 7 | fi
|
72 | 8 |
|
73 |
| -# make sure weka cluster is already up |
74 |
| -max_retries=60 |
75 |
| -for (( i=0; i < max_retries; i++ )); do |
76 |
| - if [ $(weka status | grep 'status: OK' | wc -l) -ge 1 ]; then |
77 |
| - echo "$(date -u): weka cluster is up" |
78 |
| - break |
79 |
| - fi |
80 |
| - echo "$(date -u): waiting for weka cluster to be up" |
81 |
| - sleep 30 |
82 |
| -done |
83 |
| -if (( i > max_retries )); then |
84 |
| - err_msg="timeout: weka cluster is not up after $max_retries attempts." |
85 |
| - echo "$(date -u): $err_msg" |
86 |
| - report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"$err_msg\"}" |
87 |
| - exit 1 |
88 |
| -fi |
89 |
| - |
90 |
| -cluster_size="${gateways_number}" |
91 |
| - |
92 |
| -current_mngmnt_ip=$(weka local resources | grep 'Management IPs' | awk '{print $NF}') |
93 |
| -# get container id |
94 |
| -for ((i=0; i<20; i++)); do |
95 |
| - container_id=$(weka cluster container | grep frontend0 | grep ${gateways_name} | grep $current_mngmnt_ip | grep UP | awk '{print $1}') |
96 |
| - if [ -n "$container_id" ]; then |
97 |
| - echo "$(date -u): frontend0 container id: $container_id" |
98 |
| - report "{\"hostname\": \"$HOSTNAME\", \"type\": \"progress\", \"message\": \"frontend0 container $container_id is up\"}" |
99 |
| - break |
100 |
| - fi |
101 |
| - echo "$(date -u): waiting for frontend0 container to be up" |
102 |
| - sleep 5 |
103 |
| -done |
104 |
| - |
105 |
| -if [ -z "$container_id" ]; then |
106 |
| - err_msg="Failed to get the frontend0 container ID." |
107 |
| - echo "$(date -u): $err_msg" |
108 |
| - report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"$err_msg\"}" |
109 |
| - exit 1 |
110 |
| -fi |
111 |
| - |
112 |
| -# wait for all containers to be ready |
113 |
| -max_retries=60 |
114 |
| -for (( retry=1; retry<=max_retries; retry++ )); do |
115 |
| - # get all UP gateway container ids |
116 |
| - all_container_ids=$(weka cluster container | grep frontend0 | grep ${gateways_name} | grep UP | awk '{print $1}') |
117 |
| - # if number of all_container_ids < cluster_size, do nothing |
118 |
| - all_container_ids_number=$(echo "$all_container_ids" | wc -l) |
119 |
| - if (( all_container_ids_number < cluster_size )); then |
120 |
| - echo "$(date -u): not all containers are ready - do retry $retry of $max_retries" |
121 |
| - sleep 20 |
122 |
| - else |
123 |
| - echo "$(date -u): all containers are ready" |
124 |
| - break |
125 |
| - fi |
126 |
| -done |
127 |
| - |
128 |
| -if (( retry > max_retries )); then |
129 |
| - err_msg="timeout: not all containers are ready after $max_retries attempts." |
130 |
| - echo "$(date -u): $err_msg" |
131 |
| - report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"$err_msg\"}" |
132 |
| - exit 1 |
133 |
| -fi |
134 | 9 |
|
135 | 10 | # wait for weka smb cluster to be ready in case it was created by another host
|
136 | 11 | weka smb cluster wait
|
|
0 commit comments