Need an easier way to reboot or restart an Azure Application Gateway?

3 minute read

In this scenario, I have an Azure Application Gateway (AzApplicationGateway) Platform-as-a-Service (PaaS) resource. I have experience an issue where I did not observe any incoming traffic on my logs after some minor changes to the load balancer rules and I want to restart or reboot my load balancer. But there isn’t any restart or reboot options in Azure portal, remembered I had previously published a blog post here and I have just developed a Restart-AzApplicationGateway PowerShell cmdlet for it.


Top


Problem

I need an easier way to restart or reboot an Azure Application Gateway (AzApplicationGateway).


Top


Solution

  1. Create a Restart-AzApplicationGateway.psm1 file

  2. Copy and paste the code below into the file and save it

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
<#
 .Synopsis
  Restart an Azure Application Gateway.

 .Description
  Restart an Azure Application Gateway. This function retains the existing
  Azure Application Gateway configurations prior to stop the Azure Application
  Gateway and start the Azure Application Gateway.

 .Parameter Name
  Specifies the name of the Azure Application Gateway that this cmdlet will restarts.

 .Parameter ResourceGroupName
  Specifies the name of a resource group containing the Azure Application Gateway.

 .Parameter Wait
  Specifies the number of seconds to wait before starting the Azure Application Gateway.

 .Example
  # Restart the Azure Application Gateway.
  Restart-AzApplicationGateway -Name "myAzureApplicationGateway" -ResourceGroupName "myResourceGroup"

 .Example
  # Restart the Azure Application Gateway with Verbose outputs.
  Restart-AzApplicationGateway -Name "myAzureApplicationGateway" -ResourceGroupName "myResourceGroup" -Verbose

 .Example
  # Restart the Azure Application Gateway and wait for 30 seconds duration with Verbose outputs.
  Restart-AzApplicationGateway -Name "myAzureApplicationGateway" -ResourceGroupName "myResourceGroup" -Wait 30 -Verbose

 .INPUTS
 	System.String

 .OUTPUTS
 	System.Object

 .NOTES
  Author: Ryen Tang
	GitHub: https://github.com/kiazhi
  
#>

function Restart-AzApplicationGateway {

	[CmdletBinding()]

	param (
		[Parameter( 
      Mandatory=$True, 
      ValueFromPipeline=$True, 
      ValueFromPipelineByPropertyName=$True)] 
		[String] $Name,

		[Parameter( 
      Mandatory=$True, 
      ValueFromPipeline=$True, 
      ValueFromPipelineByPropertyName=$True)] 
		[String] $ResourceGroupName,

		[Parameter( 
      Mandatory=$False, 
      ValueFromPipeline=$True, 
      ValueFromPipelineByPropertyName=$True)] 
		[Int] $Wait
	)

	begin {}

	process {

		$AzApplicationGateway = Get-AzApplicationGateway `
			-Name $Name `
			-ResourceGroupName $ResourceGroupName

		if($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
			Write-Verbose `
				-Message $("$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzzz') - " `
					+ "Get existing AzApplicationGateway configurations:")

			Write-Output `
				-InputObject $AzApplicationGateway
		}

		if($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
			Write-Verbose -Message $("$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzzz') - " `
				+ "Stopping AzApplicationGateway")
		}

		Stop-AzApplicationGateway `
			-ApplicationGateway $AzApplicationGateway `
		| Select-Object `
			-Property `
				Name, `
				ResourceGroupName, `
				OperationalState, `
				ProvisioningState

		if($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
			Write-Verbose -Message $("$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzzz') - " `
				+ "Stopped AzApplicationGateway")
		}

		if($Wait) {

			if($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
				Write-Verbose -Message $("$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzzz') - " `
					+ "Start waiting for $Wait seconds")
			}

			Start-Sleep -Seconds $Wait

			if($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
				Write-Verbose -Message $("$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzzz') - " `
					+ "End waiting")
			}
		}

		if($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
			Write-Verbose -Message $("$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzzz') - " `
				+ "Starting AzApplicationGateway")
		}

		Start-AzApplicationGateway `
			-ApplicationGateway $AzApplicationGateway `
		| Select-Object `
			-Property `
				Name, `
				ResourceGroupName, `
				OperationalState, `
				ProvisioningState

		if($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
			Write-Verbose -Message $("$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzzz') - " `
        + "Started AzApplicationGateway")
		}

  }

	end {}

}
  1. Import the Restart-AzApplicationGateway.psm1 module

  2. Type the following below.

1
Restart-AzApplicationGateway -Name "myAzureApplicationGateway" -ResourceGroupName "myAzureApplicationGatewayResourceGroup" -Verbose

Top


Update

If you are interested with the Restart-AzApplicationGateway.psm1 source code, it is currently published on Github’s kiazhi/Restart-AzApplicationGateway repository. Hope it helps to make your life easier.


Top


References


Top



Top