-
Notifications
You must be signed in to change notification settings - Fork 0
/
az-xdm-instance-upgrade.sh
executable file
·568 lines (477 loc) · 23.3 KB
/
az-xdm-instance-upgrade.sh
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
#!/bin/bash -e
# Help menu
print_help() {
cat <<-HELP
Usage: $0 <--xdm-version=version> <--resource-group=resource-group-name> [--admin-password=admin-password] [--db-server-password=db-server-password] [--repo-ro-password=repo-ro-password] [--backup-suffix=backup-suffix] [--backup]
HELP
exit 1
}
resourceGroupName=$XDM_RESOURCE_GROUP
serverPassword=$XDM_ADMIN_PASSWORD
databaseServerPassword=$XDM_DB_SERVER_PASSWORD
repositoryReadOnlyUserPassword=$XDM_RO_USER_PASSWORD
backup=false
# Parse Command Line Arguments
while [ "$#" -gt 0 ]; do
case "$1" in
--resource-group=*)
resourceGroupName="${1#*=}"
;;
--xdm-version=*)
version="${1#*=}"
;;
--admin-password=*)
serverPassword="${1#*=}"
;;
--db-server-password=*)
databaseServerPassword="${1#*=}"
;;
--repo-ro-password=*)
repositoryReadOnlyUserPassword="${1#*=}"
;;
--backup-suffix=*)
backupSuffix="${1#*=}"
;;
--backup*)
backup=true
;;
--help) print_help;;
*)
printf "************************************************************\n"
printf "* Error: Invalid argument, run --help for argument list. *\n"
printf "************************************************************\n"
exit 1
esac
shift
done
if [[ -z $version || -z $resourceGroupName ]]
then
print_help
fi
if [[ -z $serverPassword ]]
then
# Read Password
echo -n Admin Password:
read -s serverPassword
echo
fi
export AZURE_HTTP_USER_AGENT='pid-ee0cf0e2-6610-4481-9d19-e1db68621749-partnercenter'
if $backup ; then
if [[ ${#backupSuffix} -ge 7 ]]
then
echo " !! Backup suffix too long. The backup suffix length must be between 1 and 6 characters"
exit 1;
fi
if [[ -z $backupSuffix ]]
then
backupSuffix=$(LC_CTYPE=C tr -dc a-z0-9 </dev/urandom | head -c 6 ;)
echo " --> No backup suffix provided a default one will be used: $backupSuffix"
fi
fi
if ! $(az group exists --name $resourceGroupName)
then
echo " !! resource group $resourceGroupName not found."
exit 1;
fi
versionDigits=(${version//./ })
imagePublisher=semarchy
imageOffer=xdm-solution-vm
if (( ${#versionDigits[@]} == 3 )); then
if [[ ${versionDigits[2]} = "preview" ]]; then
planName=${versionDigits[0]}'_'${versionDigits[1]}'_preview'
imageVersion=latest
imageOffer=xdm-solution-vm-preview
else
planName=${versionDigits[0]}'_'${versionDigits[1]}
imageVersion=${versionDigits[0]}'.'${versionDigits[1]}'.'${versionDigits[2]}
fi
else
planName=${versionDigits[0]}'_'${versionDigits[1]}
imageVersion=latest
fi
echo " -- Plan $planName and version $imageVersion pre-upgrade checks."
# check we can find scaleSet and active vm
scaleSetName=$(az resource list --tag xdm-resource-type=ss-passive --query "[?resourceGroup=='$resourceGroupName'].name" -o tsv)
currentSsProps=$(az vmss show --name $scaleSetName --resource-group $resourceGroupName)
scaleSetId=$(echo $currentSsProps | jq -r '.id')
if [[ -z $scaleSetName ]]
then
echo " !! Scale set not found in $resourceGroupName."
exit 1;
fi
echo " -- Scale set found ($scaleSetName)."
vmActiveId=$(az resource list --tag xdm-resource-type=vm-active --query "[?resourceGroup=='$resourceGroupName'].id" -o tsv)
if [[ -z $vmActiveId ]]
then
echo " !! Active VM not found in $resourceGroupName."
exit 1;
fi
echo " -- Active VM found ($vmActiveId)."
# retrieve current vm properties
currentVmProps=$(az vm show --ids $vmActiveId)
serverUser=$(echo $currentVmProps | jq -r '.osProfile.adminUsername')
#check storage
storageName=$(az resource list --tag xdm-resource-type=storage --query "[?resourceGroup=='$resourceGroupName'].name" -o tsv)
if [[ -z $storageName ]]
then
echo " !! Storage not found in $resourceGroupName."
exit 1;
fi
echo " -- Storage found ($storageName)."
storageKey=$(az storage account keys list --account-name $storageName --resource-group $resourceGroupName | jq -r '.[0].value')
dbServerId=$(az resource list --tag xdm-resource-type=db-server --query "[?resourceGroup=='$resourceGroupName'].id" -o tsv)
if [[ -z $dbServerId ]]
then
echo " !! Database server not found in $resourceGroupName."
exit 1;
fi
# retrieve current db properties
currentDbServerProps=$(az resource show --ids $dbServerId)
dbType=$(echo $currentDbServerProps | jq -r '.tags."xdm-database-type"')
echo " -- $dbType database server found ($dbServerId)."
databaseAdminUser=$(echo $currentDbServerProps | jq -r '.properties.administratorLogin')
databaseServerName=$(echo $currentDbServerProps | jq -r '.name')
zone=$(date +%z)
datetime=$(date +%Y-%m-%dT%H:%M:%S)
now=$(echo $datetime${zone:0:3}:${zone:3:2})
echo " --> Checking admin credentials..."
vmName=$(echo $currentVmProps | jq -r '.name')
echo "########## Running script ##########"
printf "az vm extension set --resource-group $resourceGroupName \\
--vm-name $vmName \\
--name customScript \\
--publisher Microsoft.Azure.Extensions \\
--protected-settings '{\"commandToExecute\": \"/usr/local/xdm/bin/check-admin-credentials-ubuntu.sh --server-user=\"'$serverUser'\" --server-password=\"<password>\"\"}'\n"
echo "####################################"
az vm extension set --resource-group $resourceGroupName \
--vm-name $vmName \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--protected-settings '{"commandToExecute": "/usr/local/xdm/bin/check-admin-credentials-ubuntu.sh --server-user=\"'$serverUser'\" --server-password=\"'$serverPassword'\""}'
echo " --> Upgrade can proceed. Moving current xDM instance to new version..."
az vm image terms accept --publisher $imagePublisher --offer $imageOffer --plan $planName
oldPlanName=$(echo $currentVmProps | jq -r '.storageProfile.imageReference.sku')
oldImagePublisher=$(echo $currentVmProps | jq -r '.storageProfile.imageReference.publisher')
oldImageOffer=$(echo $currentVmProps | jq -r '.storageProfile.imageReference.offer')
oldImageVersion=$(echo $currentVmProps | jq -r '.storageProfile.imageReference.exactVersion')
majorUpgrade=false
oldVersionDigits=(${oldImageVersion//./ })
if [[ ${versionDigits[1]} = ${oldVersionDigits[1]} ]]; then
echo " --> Executing a minor upgrade..."
elif (( versionDigits[1] > oldVersionDigits[1] )); then
if [[ ${versionDigits[1]} = 3 ]]; then
if ! $backup ; then
while true; do
read -p "The --backup option was not provided, no backup of the existing resources will be performed. Are you running the upgrade on a cloned or a backed-up instance? (yes/no) " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) while true; do
read -p "Are you sure you want to proceed? (yes/no) " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
echo " --> Executing a major upgrade..."
majorUpgrade=true
if [[ -z $databaseServerPassword ]]
then
# Read Password
echo -n Database Server Password:
read -s databaseServerPassword
echo
fi
if [[ -z $repositoryReadOnlyUserPassword ]]
then
# Read Password
echo -n Repository read-only user Password:
read -s repositoryReadOnlyUserPassword
echo
fi
else
echo " !! Version upgrade is only possible from 5.1.x or 5.2.x to 5.3.y"
exit 1;
fi
else
echo " !! Version downgrade is not supported"
exit 1;
fi
if $backup ; then
echo " --> Creating backup for databases..."
if [[ $dbType = "PostgreSQL" ]]; then
echo "########## Running script ##########"
printf "az postgres server restore --restore-point-in-time $now \\
--resource-group $resourceGroupName \\
--source-server $databaseServerName \\
--name $databaseServerName-$backupSuffix\n"
echo "####################################"
az postgres server restore --restore-point-in-time $now \
--resource-group $resourceGroupName \
--source-server $databaseServerName \
--name $databaseServerName-$backupSuffix
else
for databaseName in $(az sql db list --ids $dbServerId | jq -r '.[] | select(.name != "master") | .name '); do
echo "########## Running script ##########"
printf "az sql db restore --time $now \\
--resource-group $resourceGroupName \\
--server $databaseServerName \\
--name $databaseName \\
--dest-name $databaseName-$backupSuffix\n"
echo "####################################"
az sql db restore --time $now \
--resource-group $resourceGroupName \
--server $databaseServerName \
--name $databaseName \
--dest-name $databaseName-$backupSuffix
done
fi
echo " --> Creating backup scale set image..."
echo "########## Running script ##########"
printf "az vmss create --resource-group $resourceGroupName \\
--name $scaleSetName-$backupSuffix \\
--admin-password <password> \\
--admin-username $serverUser \\
--authentication-type password \\
--app-gateway '' \\
--computer-name-prefix $(echo $currentSsProps | jq -r '.virtualMachineProfile.osProfile.computerNamePrefix') \\
--image $oldImagePublisher:$oldImageOffer:$oldPlanName:$oldImageVersion \\
--instance-count 1 \\
--plan-name $oldPlanName \\
--plan-product $oldImageOffer \\
--plan-publisher $oldImagePublisher \\
--location $(echo $currentSsProps | jq -r '.location') \\
--subnet $(echo $currentSsProps | jq -r '.virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].subnet.id') \\
--tags xdm-resource-type=ss-passive-backup \\
--upgrade-policy-mode $(echo $currentSsProps | jq -r '.upgradePolicy.mode') \\
--vm-sku $(echo $currentSsProps | jq -r '.sku.name')\n"
echo "####################################"
az vmss create --resource-group $resourceGroupName \
--name $scaleSetName-$backupSuffix \
--admin-password "$serverPassword" \
--admin-username "$serverUser" \
--authentication-type password \
--app-gateway "" \
--computer-name-prefix $(echo $currentSsProps | jq -r '.virtualMachineProfile.osProfile.computerNamePrefix') \
--image $oldImagePublisher:$oldImageOffer:$oldPlanName:$oldImageVersion \
--instance-count 1 \
--plan-name $oldPlanName \
--plan-product $oldImageOffer \
--plan-publisher $oldImagePublisher \
--location $(echo $currentSsProps | jq -r '.location') \
--subnet $(echo $currentSsProps | jq -r '.virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].subnet.id') \
--tags xdm-resource-type=ss-passive-backup \
--upgrade-policy-mode $(echo $currentSsProps | jq -r '.upgradePolicy.mode') \
--vm-sku $(echo $currentSsProps | jq -r '.sku.name')
echo "########## Running script ##########"
printf "az vmss extension set \\
--resource-group $resourceGroupName \\
--vmss-name $scaleSetName-$backupSuffix \\
--name customScript \\
--publisher Microsoft.Azure.Extensions \\
--protected-settings {\"commandToExecute\": \"/usr/local/xdm/bin/init-ss-ubuntu.sh --storage-name=\"$storageName\" --storage-key=<storage key> --storage-folder=xdm-assets --server-user=\"$serverUser\" --server-password=<server password> \"}\n"
echo "####################################"
az vmss extension set \
--resource-group $resourceGroupName \
--vmss-name $scaleSetName-$backupSuffix \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--protected-settings '{"commandToExecute": "/usr/local/xdm/bin/init-ss-ubuntu.sh --storage-name=\"'$storageName'\" --storage-key=\"'$storageKey'\" --storage-folder=xdm-assets --server-user=\"'$serverUser'\" --server-password=\"'$serverPassword'\""}'
echo " -- Backup scale set image created."
echo " --> Creating backup Active VM..."
echo "########## Running script ##########"
printf "az vm create --resource-group $resourceGroupName \\
--name $vmName-$backupSuffix \\
--admin-password <password> \\
--admin-username $serverUser \\
--authentication-type password \\
--computer-name $(echo $currentVmProps | jq -r '.osProfile.computerName') \\
--image $oldImagePublisher:$oldImageOffer:$oldPlanName:$oldImageVersion \\
--plan-name $oldPlanName \\
--plan-product $oldImageOffer \\
--plan-publisher $oldImagePublisher \\
--location $(echo $currentVmProps | jq -r '.location') \\
--nsg '' \\
--public-ip-address '' \\
--os-disk-caching $(echo $currentVmProps | jq -r '.storageProfile.osDisk.caching') \\
--os-disk-size-gb $(echo $currentVmProps | jq -r '.storageProfile.osDisk.diskSizeGb') \\
--size $(echo $currentVmProps | jq -r '.hardwareProfile.vmSize') \\
--tags xdm-resource-type=vm-active-backup\n"
echo "####################################"
az vm create --resource-group $resourceGroupName \
--name $vmName-$backupSuffix \
--admin-password "$serverPassword" \
--admin-username "$serverUser" \
--authentication-type password \
--computer-name $(echo $currentVmProps | jq -r '.osProfile.computerName') \
--image $oldImagePublisher:$oldImageOffer:$oldPlanName:$oldImageVersion \
--plan-name $oldPlanName \
--plan-product $oldImageOffer \
--plan-publisher $oldImagePublisher \
--location $(echo $currentVmProps | jq -r '.location') \
--nsg "" \
--public-ip-address "" \
--os-disk-caching $(echo $currentVmProps | jq -r '.storageProfile.osDisk.caching') \
--os-disk-size-gb $(echo $currentVmProps | jq -r '.storageProfile.osDisk.diskSizeGb') \
--size $(echo $currentVmProps | jq -r '.hardwareProfile.vmSize') \
--tags xdm-resource-type=vm-active-backup
echo " -- Backup Active VM created."
fi
if $majorUpgrade ; then
echo " --> Saving semarchy.xml and tomcat-users.xml to semarchy.xml-old and tomcat-users.xml-old..."
vmName=$(echo $currentVmProps | jq -r '.name')
echo "########## Running script ##########"
printf "az vm extension set --resource-group $resourceGroupName \\
--vm-name $vmName \\
--name customScript \\
--publisher Microsoft.Azure.Extensions \\
--protected-settings '{\"commandToExecute\": \"mv /mnt/xdm/conf/semarchy.xml /mnt/xdm/conf/semarchy.xml-old ; mv /mnt/xdm/conf/tomcat-users.xml /mnt/xdm/conf/tomcat-users.xml-old\"}'\n"
echo "####################################"
az vm extension set --resource-group $resourceGroupName \
--vm-name $vmName \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--protected-settings '{"commandToExecute": "mv /mnt/xdm/conf/semarchy.xml /mnt/xdm/conf/semarchy.xml-old ; mv /mnt/xdm/conf/tomcat-users.xml /mnt/xdm/conf/tomcat-users.xml-old"}'
echo " --> Deleting obsolete scale set image ($scaleSetName)..."
az vmss delete --ids $scaleSetId
az resource wait --deleted --ids $scaleSetId
echo " -- Obsolete scale set image deleted."
echo " --> Re-creating scale set image..."
echo "########## Running script ##########"
appGateway=$(echo $currentSsProps | jq -r '.virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].applicationGatewayBackendAddressPools[0].id' | sed 's/\/backendAddressPools.*//')
backendPoolName=$(echo $currentSsProps | jq -r '.virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].applicationGatewayBackendAddressPools[0].id' | sed 's/.*\/backendAddressPools\///')
printf "az vmss create --resource-group $resourceGroupName \\
--name $scaleSetName \\
--admin-password <password> \\
--admin-username $serverUser \\
--authentication-type password \\
--app-gateway $appGateway \\
--backend-pool-name $backendPoolName \\
--computer-name-prefix $(echo $currentSsProps | jq -r '.virtualMachineProfile.osProfile.computerNamePrefix') \\
--image $imagePublisher:$imageOffer:$planName:$imageVersion \\
--instance-count $(echo $currentSsProps | jq -r '.sku.capacity') \\
--plan-name $planName \\
--plan-product $imageOffer \\
--plan-publisher $imagePublisher \\
--location $(echo $currentSsProps | jq -r '.location') \\
--subnet $(echo $currentSsProps | jq -r '.virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].subnet.id') \\
--tags xdm-resource-type=ss-passive \\
--upgrade-policy-mode $(echo $currentSsProps | jq -r '.upgradePolicy.mode') \\
--vm-sku $(echo $currentSsProps | jq -r '.sku.name')\n"
echo "####################################"
az vmss create --resource-group $resourceGroupName \
--name $scaleSetName \
--admin-password "$serverPassword" \
--admin-username "$serverUser" \
--authentication-type password \
--app-gateway $appGateway \
--backend-pool-name $backendPoolName \
--computer-name-prefix $(echo $currentSsProps | jq -r '.virtualMachineProfile.osProfile.computerNamePrefix') \
--image $imagePublisher:$imageOffer:$planName:$imageVersion \
--instance-count $(echo $currentSsProps | jq -r '.sku.capacity') \
--plan-name $planName \
--plan-product $imageOffer \
--plan-publisher $imagePublisher \
--location $(echo $currentSsProps | jq -r '.location') \
--subnet $(echo $currentSsProps | jq -r '.virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].subnet.id') \
--tags xdm-resource-type=ss-passive \
--upgrade-policy-mode $(echo $currentSsProps | jq -r '.upgradePolicy.mode') \
--vm-sku $(echo $currentSsProps | jq -r '.sku.name')
echo " -- scale set image created."
else
echo " --> Updating scale set image..."
az vmss update --name $scaleSetName --resource-group $resourceGroupName --set virtualMachineProfile.storageProfile.imageReference.version=$imageVersion
echo " -- Scale set updated."
fi
echo " --> Deleting obsolete active VM ($vmActiveId)..."
az vm delete --ids $vmActiveId --yes
az resource wait --deleted --ids $vmActiveId
echo " -- Obsolete active VM deleted."
echo " --> Re-creating Active VM..."
echo "########## Running script ##########"
printf "az vm create --resource-group $resourceGroupName \\
--name $vmName \\
--admin-password <password> \\
--admin-username $serverUser \\
--authentication-type password \\
--computer-name $(echo $currentVmProps | jq -r '.osProfile.computerName') \\
--image $imagePublisher:$imageOffer:$planName:$imageVersion \\
--plan-name $planName \\
--plan-product $imageOffer \\
--plan-publisher $imagePublisher \\
--location $(echo $currentVmProps | jq -r '.location') \\
--nics $(echo $currentVmProps | jq -r '.networkProfile.networkInterfaces[0].id') \\
--os-disk-caching $(echo $currentVmProps | jq -r '.storageProfile.osDisk.caching') \\
--os-disk-size-gb $(echo $currentVmProps | jq -r '.storageProfile.osDisk.diskSizeGb') \\
--size $(echo $currentVmProps | jq -r '.hardwareProfile.vmSize') \\
--tags xdm-resource-type=vm-active\n"
echo "####################################"
az vm create --resource-group $resourceGroupName \
--name $vmName \
--admin-password "$serverPassword" \
--admin-username "$serverUser" \
--authentication-type password \
--computer-name $(echo $currentVmProps | jq -r '.osProfile.computerName') \
--image $imagePublisher:$imageOffer:$planName:$imageVersion \
--plan-name $planName \
--plan-product $imageOffer \
--plan-publisher $imagePublisher \
--location $(echo $currentVmProps | jq -r '.location') \
--nics $(echo $currentVmProps | jq -r '.networkProfile.networkInterfaces[0].id') \
--os-disk-caching $(echo $currentVmProps | jq -r '.storageProfile.osDisk.caching') \
--os-disk-size-gb $(echo $currentVmProps | jq -r '.storageProfile.osDisk.diskSizeGb') \
--size $(echo $currentVmProps | jq -r '.hardwareProfile.vmSize') \
--tags xdm-resource-type=vm-active
echo " -- Active VM created."
echo " --> Running upgrade script..."
echo "########## Running script ##########"
if $majorUpgrade ; then
printf "az vm extension set \\
--resource-group $resourceGroupName \\
--vm-name $vmName \\
--name customScript \\
--publisher Microsoft.Azure.Extensions \\
--protected-settings {\"commandToExecute\": \"/usr/local/xdm/bin/upgrade-instance-ubuntu.sh --storage-name=\"$storageName\" --storage-key=<storage key> --storage-folder=xdm-assets --server-user=\"$serverUser\" --server-password=<server password> --db-type='$dbType' --db-admin=\"$databaseAdminUser\" --db-password=<db password> --db-server=\"$databaseServerName\" --repo-ro-password=<repo ro password> --major-upgrade \"}\n"
echo "####################################"
az vm extension set \
--resource-group $resourceGroupName \
--vm-name $vmName \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--protected-settings '{"commandToExecute": "/usr/local/xdm/bin/upgrade-instance-ubuntu.sh --storage-name=\"'$storageName'\" --storage-key=\"'$storageKey'\" --storage-folder=xdm-assets --server-user=\"'$serverUser'\" --server-password=\"'$serverPassword'\" --db-type='$dbType' --db-admin=\"'$databaseAdminUser'\" --db-password=\"'$databaseServerPassword'\" --db-server=\"'$databaseServerName'\" --repo-ro-password=\"'$repositoryReadOnlyUserPassword'\" --major-upgrade"}'
echo "########## Running script ##########"
printf "az vmss extension set \\
--resource-group $resourceGroupName \\
--vmss-name $scaleSetName \\
--name customScript \\
--publisher Microsoft.Azure.Extensions \\
--protected-settings {\"commandToExecute\": \"/usr/local/xdm/bin/init-ss-ubuntu.sh --storage-name=\"$storageName\" --storage-key=<storage key> --storage-folder=xdm-assets --server-user=\"$serverUser\" --server-password=<server password> \"}\n"
echo "####################################"
az vmss extension set \
--resource-group $resourceGroupName \
--vmss-name $scaleSetName \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--protected-settings '{"commandToExecute": "/usr/local/xdm/bin/init-ss-ubuntu.sh --storage-name=\"'$storageName'\" --storage-key=\"'$storageKey'\" --storage-folder=xdm-assets --server-user=\"'$serverUser'\" --server-password=\"'$serverPassword'\""}'
else
printf "az vm extension set \\
--resource-group $resourceGroupName \\
--vm-name $vmName \\
--name customScript \\
--publisher Microsoft.Azure.Extensions \\
--protected-settings {\"commandToExecute\": \"/usr/local/xdm/bin/upgrade-instance-ubuntu.sh --storage-name=\"$storageName\" --storage-key=<storage key> --storage-folder=xdm-assets --server-user=\"$serverUser\" --server-password=<server password>\"}\n"
echo "####################################"
az vm extension set \
--resource-group $resourceGroupName \
--vm-name $vmName \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--protected-settings '{"commandToExecute": "/usr/local/xdm/bin/upgrade-instance-ubuntu.sh --storage-name=\"'$storageName'\" --storage-key=\"'$storageKey'\" --storage-folder=xdm-assets --server-user=\"'$serverUser'\" --server-password=\"'$serverPassword'\""}'
fi
echo " -- Upgrade script completed."
echo " -- Instance upgraded successfully."