Skip to content

Commit

Permalink
Fix handling of existing w3wp processes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 7, 2021
1 parent 25706e5 commit d2a28ce
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Server.Installer/Services/ServerInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,20 @@ public async Task PerformInstall(CliParams cliParams)
// website process first.
if (cliParams.WebServer == WebServerType.IisWindows)
{
var initialW3wpCount = Process.GetProcessesByName("w3wp").Length;
Process.Start("powershell.exe", "-Command & \"{ Stop-WebAppPool -Name Remotely -ErrorAction SilentlyContinue }\"").WaitForExit();
Process.Start("powershell.exe", "-Command & \"{ Stop-Website -Name Remotely -ErrorAction SilentlyContinue }\"").WaitForExit();
ConsoleHelper.WriteLine("Waiting for w3wp processes to close...");
TaskHelper.DelayUntil(() => Process.GetProcessesByName("w3wp").Length < initialW3wpCount, TimeSpan.FromMinutes(5), 100);
var w3wpProcs = Process.GetProcessesByName("w3wp");
if (w3wpProcs.Length > 0)
{
Process.Start("powershell.exe", "-Command & \"{ Stop-WebAppPool -Name Remotely -ErrorAction SilentlyContinue }\"").WaitForExit();
Process.Start("powershell.exe", "-Command & \"{ Stop-Website -Name Remotely -ErrorAction SilentlyContinue }\"").WaitForExit();

ConsoleHelper.WriteLine("Waiting for w3wp processes to close...");
foreach (var proc in w3wpProcs)
{
try { proc.Kill(); }
catch { }
}
TaskHelper.DelayUntil(() => Process.GetProcessesByName("w3wp").Length < w3wpProcs.Length, TimeSpan.FromMinutes(5), 100);
}
}

ConsoleHelper.WriteLine("Extracting files.");
Expand Down

0 comments on commit d2a28ce

Please sign in to comment.