0

we have a problem with a Microsoft bot hosted in Azure. As long as we haven't resolved it, we want to periodically restart it.

We found 3 sets of powershell commands and spent the full day on it without making it work.

Solution 1:

  • we found the cmdlets : Get-AzCloudService Restart-AzCloudService.
  • We didn't understand from the documentation what module to install.
  • It returns : The term 'Restart-AzCloudService' is not recognized as the name of a cmdlet.
  • They talk about an obscure "extended support" to have access to it.

Solution 2:

We are able to list the cloud service using:

  • Connect-AzAccount
  • get-azresource -name $serviceName -resourcetype "Microsoft.BotService/botServices"

But we do not find the cmdlet to restart the resource.

Solution 3:

  • Reset-AzureRoleInstance -serviceName $serviceName -Slot "production" -InstanceName $serviceName
  • Error : No default subscription has been designated. Use Select-AzureSubscription -Default
  • We are using MFA. Login-AzureRmAccount systematically fails , evenly saying that our account is disabled.

We did no manager to run the sequence:

  • Login-AzureRmAccount
  • Select-AzureSubscription -Default
  • Reset-AzureRoleInstance -serviceName $serviceName -Slot "production" -InstanceName $serviceName

The idea is to run this script twice a day, either from a VM or from an Azure Runbook. We managed to run this code using an automation Account but we are still missing the last command that would restart the bot (that we consider a cloud service).

Param()
$automationAccount = "xxx"
$resourceGroup = "xxx"
$serviceName = "xxx"
$subscriptionname ="xxx"
$subscriptionid ="xxx"

# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process | Out-Null

# Connect using a Managed Service Identity
try {
    $AzureContext = (Connect-AzAccount -Identity).context
}
catch{
    Write-Output "There is no system-assigned user identity. Aborting."; 
    exit
}

#Set-AzureSubscription  -SubscriptionId $subscriptionid
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription `
 -DefaultProfile $AzureContext

get-azresource -name $serviceName -resourcetype "Microsoft.BotService/botServices" 
CloudAnywhere
  • 669
  • 1
  • 11
  • 27
  • When you say `Cloud Service`, what do you exactly mean? There's actually a service (product) in Azure called `Cloud Service` which was one of the first PaaS services offered by Azure to run your web application/background tasks using something called Web/Worker roles respectively. – Gaurav Mantri Oct 14 '21 at 15:45
  • Correct. I'm trying to restart this type of resource named Cloud Service. (more precisely, the bot is deployed in a container whose type is "App Service" in Azure.). This is ultimately what I'm trying to restart. – CloudAnywhere Oct 15 '21 at 11:58
  • You can refer to [Is there anyway to restart an Azure classic cloud service role every interval?](https://stackoverflow.com/questions/53823320/is-there-anyway-to-restart-an-azure-classic-cloud-service-role-every-interval). You can also open an issue on GitHub: [Azure/azure-powershell](https://github.com/Azure/azure-powershell/issues) – Ecstasy Oct 19 '21 at 09:02
  • Did you have any joy with this? I have the same issue when trying to do this from a DevOps Pipeline. – Max Power Sep 05 '22 at 06:58

0 Answers0