Force restart your Azure App service site and host

Published on June 22, 2021

Sometimes your Azure App service host will need to be restarted. You can do this but it’s hidden away in the Azure resource manager site. Here’s how to find it!

Why restart the host

Sometimes your app service host can get into a broken state or you want make sure that it is in a fresh state.

For example I had to do this recently when trying to upgrade an App Services site to Node.js 14 and it failed because PM2 was missing on the App Service Linux container.

You might see errors like the following that the App service instance doesn’t recover from

[error]Error: Failed to swap App Service 'YOUR_SITE' slots - 'staging' and 'production'. Error: ExpectationFailed - Cannot swap site slots for site 'YOUR_SITE' because the 'staging' slot did not respond to http ping. (CODE: 417)
[error]Error: Failed to swap App Service 'YOUR_SITE' slots - 'staging' and 'production'. Error: Conflict - Cannot modify this site because another operation is in progress. Details: Id: 45210a29, OperationName: SwapSiteSlots, CreatedTime: 5/20/2021 2:01:30 AM, WebSystemName: websites, SubscriptionName: , WebspaceName: YOUR_SITE, SiteName: ***, SlotName: staging, ServerFarmName: , GeoOperationId: (null) (CODE: 409)

Azure resource manager

Azure provides a nice ARM interface of all your resources at https://resources.azure.com.

If you work with Azure resources then it’s worth getting familiar with this interface - you can use it to quickly extract ARM template details, you can easily update settings and fully manage the resources you have access to using the Azure Api through the website.

Find the App Service Resource

To find the app service resource you have to dig in to the tree menu on the left. The path is:

Subscriptions > YOUR_SUBSCRIPTION > resourceGroups > YOUR_RESOURCE_GROUP > providers > Microsoft.Web > sites > YOUR_SITE

and select the site name. Make sure you select the site name! You should see something like

{
  "id": "/subscriptions/...",
  "name": "YOUR_SITE",
  "type": "Microsoft.Web/sites",

Note if you are trying to restart a slot you need to go a step further in the tree:

Subscriptions > YOUR_SUBSCRIPTION > resourceGroups > YOUR_RESOURCE_GROUP > providers > Microsoft.Web > sites > YOUR_SITE > slots > YOUR_SLOT_NAME

Change the interface to edit mode

Click the big Edit button!

Edit button
Edit button

How to turn off the site instance

Find the section below and change “Running” to “Stopped”

 "properties": {
    "name": "YOUR_SITE",
    "state": "Running",
    "hostNames": [
      "YOUR_SITE.azurewebsites.net"
    ],
 "properties": {
    "name": "YOUR_SITE",
    "state": "Stopped",
    "hostNames": [
      "YOUR_SITE.azurewebsites.net"
    ],

Turn off the App Services host

You have to find this setting and change it to true

    "scmSiteAlsoStopped": false,
    "scmSiteAlsoStopped": true,

Save

To save your changes click on the PUT button.

Darragh ORiordan

Hi! I'm Darragh ORiordan.

I live and work in Sydney, Australia building and supporting happy teams that create high quality software for the web.

I also make tools for busy developers! Do you have a new M1 Mac to setup? Have you ever spent a week getting your dev environment just right?

My Universal DevShell tooling will save you 30+ hours of configuring your Windows or Mac dev environment with all the best, modern shell and dev tools.

Get DevShell here: ✨ https://usemiller.dev/dev-shell


Read more articles like this one...

List of article summaries

#devops

Extract user profile attributes from an Azure ADB2C tenant using the Microsoft Graph API

I had to retrieve a list of users from an Azure Active Directory B2C instance today. I thought I could just go through the Azure UI but that’s limited to short pages of data and limited attributes.

There is a CSV export provided on the UI but you won’t get the required identity objects in the csv output if you need a user’s signin email address.

I had to use the Microsoft Graph Api to get what I needed. This is a bit hacky but it does the trick!

#devops

Scheduling a feature toggle using no-code with Azure Logic Apps

I use launch darkly to toggle features on an app. There is one third-party dependency that has regular scheduled maintenance and I need to toggle the feature on and off on schedule.

Launch Darkly has built in scheduling to handle this scenario but you have to be on the enterprise plan to use it. The enterprise plan is too expensive to upgrade to for scheduling alone so I needed to find a different way to automate this.

#frontend-development

Avoid rebuild of React App in every CI stage

If you have a react app you can use env vars like REACT_APP_MY_ENV_VAR in your application and React will automatically pull them in to your app when you build the production application.

This is very useful but if you have variables that change for each environment and your application build takes a long time, you might want to avoid building unnecessarily in CI. For example you might have a QA environment and a Staging environment that have different configuration.

We type-check our code on each build and that was taking 5 minutes+ to build each environment so we had to make it faster. We changed our app from using REACT_APP env vars to using a configuration file that we could quickly write to using CI.

Our CI system is Azure DevOops so the CI scripts here are specifically for Azure DevOps but they apply to most CI systems with small changes.

The real work happens in a Node.js script that would work anywhere.

Comments