Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/commands/restartWebApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { type WebSiteManagementClient } from "@azure/arm-appservice";
import { type IActionContext } from "@microsoft/vscode-azext-utils";
import { commands } from "vscode";
import { ext } from "../extensionVariables";
import { localize } from "../localize";
import { type SiteTreeItem } from "../tree/SiteTreeItem";
import { createWebSiteClient } from "../utils/azureClients";
import { pickWebApp } from "../utils/pickWebApp";

export async function restartWebApp(context: IActionContext, node?: SiteTreeItem): Promise<void> {
node ??= await pickWebApp(context);
await commands.executeCommand('appService.Stop', node);
await commands.executeCommand('appService.Start', node);

await node.initSite(context);
const site = node.site;
const client: WebSiteManagementClient = await createWebSiteClient([context, node.subscription]);
const restartingApp: string = localize('restartingApp', 'Restarting "{0}"...', site.fullName);
const restartedApp: string = localize('restartedApp', '"{0}" has been restarted.', site.fullName);
await node.runWithTemporaryDescription(context, localize('restarting', "Restarting..."), async () => {
ext.outputChannel.appendLog(restartingApp);
if (site.slotName) {
await client.webApps.restartSlot(site.resourceGroup, site.siteName, site.slotName);
} else {
await client.webApps.restart(site.resourceGroup, site.siteName);
}
ext.outputChannel.appendLog(restartedApp);
});
}