1
+ #! /bin/bash
2
+ set -e
3
+ printf " \n=== Managing Web App Slot in Azure ===\n"
4
+
5
+ pingwebapp () {
6
+ # a helper function to ping a webapp
7
+ }
8
+
9
+ # setup
10
+ printf " \nSetup: Creating a new resource group: %s at location: %s.\n" " $groupName " " $location "
11
+
12
+ appName=` randomName testweb`
13
+ slotname1=" staging"
14
+ slotname2=" testing"
15
+ planName=` randomName testplan`
16
+ tier=" Standard"
17
+ apiversion=" 2015-08-01"
18
+ resourceType=" Microsoft.Web/sites"
19
+
20
+ azure group create --name " $groupName " --location " $location "
21
+
22
+ printf " \n1. Create a new app service plan %s " " $planName "
23
+ azure app service plan create -n " $planName " -g " $groupName " -l " $location " --tier " $tier "
24
+
25
+ printf " \n2. Create a new web app %s " " $appName "
26
+ webappInfo=` azure webapp create -g " $groupName " -n " $appName " -l " $location " --plan " $planName " `
27
+
28
+ printf " \nValidating web app name %s " " $appName "
29
+ [ $( echo $webappInfo | jq ' .name' --raw-output) == " $appName " ]
30
+
31
+ printf " \n3. Create a web app slot %s " " $slotname1 "
32
+ slot1=` azure webapp slot create -g " $groupName " --plan " $planName " -n " $appName " --slot " $slotname1 " `
33
+ appWithSlotName1=" $appName /$slotname1 "
34
+
35
+ printf " \nValidating web app slot %s " " $slotname1 "
36
+ [ $( echo $slot1 | jq ' .name' --raw-output) == " $appWithSlotName1 " ]
37
+
38
+ printf " \nValidating web app slot get for %s " " $slotname1 "
39
+ slot1=` azure webapp slot get -g " $groupName " -n " $appName " --slot " $slotname1 " `
40
+ [ $( echo $slot1 | jq ' .name' --raw-output) == " $appWithSlotName1 " ]
41
+
42
+ printf " \nValidating web app slot via pipline obj for %s " " $slotname1 "
43
+ slot1=` echo " $webappInfo " | azure webapp slot get --slot " $slotname1 " `
44
+
45
+ printf " \n4. Create another web app slot %s " " $slotname2 "
46
+ slot2=` azure webapp slot create -g " $groupName " --plan " $planName " -n " $appName " --slot " $slotname2 " `
47
+ appWithSlotName2=" $appName /$slotname2 "
48
+
49
+ printf " \n5. Get the webapp slots:"
50
+ slots=` azure webapp slot get -g " $groupName " -n " $appName " `
51
+ slotN1=` echo $slots | jq ' .[0].name' `
52
+ slotN2=` echo $slots | jq ' .[1].name' `
53
+ slotNames=` echo $slotN1 $slotN2 `
54
+
55
+ printf " \nValidating web app slots %s " " $slotname1 and $slotname2 "
56
+ [[ $slotNames == * " $appWithSlotName1 " * ]]
57
+ [[ $slotNames == * " $appWithSlotName2 " * ]]
58
+
59
+ printf " \n6. Change web app slot %s service plan" " $slotname2 "
60
+ printf " \n7. Set web app slot %s config properties" " $slotname2 "
61
+ printf " \n8. Set web app slot %s settings and connection strings" " $slotname2 "
62
+
63
+ printf " \n9. Get web app slot %s publishing profile" " $slotname1 "
64
+ printf " \n10. Get web app slot %s publishing profile via pipline obj" " $slotname1 "
65
+
66
+ printf " \n11. Get web app slot metrics %s " " $slotname1 "
67
+ for i in {1..10}
68
+ do
69
+ pingwebapp $slot1
70
+ done
71
+
72
+ endTime=` date +" %A, %B %d, %Y %X" `
73
+ startTime=` date +" %A, %B %d, %Y %X" --date " 3 hour ago" `
74
+ $metricsNames =" \" ('CPU', 'Requests')\" "
75
+
76
+ # !Not able to test since complex object issue.
77
+ metrics=` azure webapp slot metrics get -g " $groupName " -n " $appName " --slot " $slotname1 " --granularity PT1M --starttime " $startTime " --endtime " $endTime " --metrics " $metricsNames " `
78
+
79
+ printf " \nValidating web app slot metrics %s " " $slotname1 "
80
+ for i in $metricsNames
81
+ do
82
+ [ $( echo $metrics ) == " $i " ]
83
+ done
84
+
85
+ # !Not able to test pipeline for now
86
+ printf " \nValidating web app slot metrics via pipline obj %s " " $slotname1 "
87
+
88
+ printf " \n12. Stop web app slot: %s." " $slotname1 "
89
+ slot1=` echo " $slot1 " | azure webapp slot stop`
90
+ printf " \nValidating web app slot %s stopped " " $slotname1 "
91
+ [ $( echo $slot1 | jq ' ."properties.state"' --raw-output) == " Stopped" ]
92
+
93
+ printf " \n13 Stop web app slot: %s." " $slotname1 "
94
+ slot1=` echo " $slot1 " | azure webapp slot start`
95
+ printf " \nValidating web app slot %s running " " $slotname1 "
96
+ [ $( echo $slot1 | jq ' ."properties.state"' --raw-output) == " Running" ]
97
+
98
+ printf " \n14 Stop web app slot: %s." " $slotname1 "
99
+ slot1=` echo " $slot1 " | azure webapp slot stop`
100
+ printf " \nValidating web app slot %s stopped " " $slotname1 "
101
+ [ $( echo $slot1 | jq ' ."properties.state"' --raw-output) == " Stopped" ]
102
+
103
+ printf " \n15 Stop web app slot: %s." " $slotname1 "
104
+ slot1=` echo " $slot1 " | azure webapp slot start`
105
+ printf " \nValidating web app slot %s running " " $slotname1 "
106
+ [ $( echo $slot1 | jq ' ."properties.state"' --raw-output) == " Running" ]
107
+
108
+ printf " \n16 Restart web app slot: %s." " $slotname1 "
109
+ slot1=` echo " $slot1 " | azure webapp slot restart`
110
+ printf " \nValidating web app slot %s Running " " $slotname1 "
111
+ [ $( echo $slot1 | jq ' ."properties.state"' --raw-output) == " Running" ]
112
+
113
+ printf " \n17 Restart web app slot: %s." " $slotname1 "
114
+ slot1=` echo " $slot1 " | azure webapp slot restart`
115
+ printf " \nValidating web app slot %s Running " " $slotname1 "
116
+ [ $( echo $slot1 | jq ' ."properties.state"' --raw-output) == " Running" ]
117
+
118
+ # Clone ------
119
+ # !Not able to test since complex object input issue.
120
+ # printf "\n10. Clone web app slot: %s." "$slotname1"
121
+ # slotClone=`azure web app slot clone`
122
+ # appWithSlotNameClone="$appName/slotname1"
123
+
124
+ # printf "\nValidating cloned web app slot %s " "$slotname1"
125
+ # [ $(echo $slotClone | jq '.name' --raw-output) == "$appWithSlotNameClone" ]
126
+
127
+ # printf "\nValidating web app slot get for %s " "$slotname1"
128
+ # slot1=`azure webapp slot get -g "$groupName" -n "$appName" --slot "$slotname1"`
129
+ # [ $(echo $slot1 | jq '.name' --raw-output) == "$appWithSlotNameClone" ]
130
+ # -------
131
+
132
+ # Cleanup
133
+ printf " \n20. Remove web app slot: %s." " $slotname1 "
134
+ azure webapp slot remove -g " $groupName " -n " $appName " --slot " $slotname1 "
135
+
136
+ printf " \n20. Remove web app: %s." " $appName "
137
+ azure webapp remove -g " $groupName " -n " $appName "
138
+
139
+ printf " \n20. Remove app service plan: %s." " $planName "
140
+ azure app service plan remove -g " $groupName " -n " $planName "
141
+
142
+ printf " \n20. Remove resource group: %s." " $groupName "
0 commit comments