Stabilizing IIS helpers.
This commit is contained in:
parent
9eca47b388
commit
c44e65c27f
|
|
@ -195,6 +195,7 @@ namespace DeploymentHelpers
|
||||||
|
|
||||||
protected void TriggerHostShutdown(CancellationTokenSource hostShutdownSource)
|
protected void TriggerHostShutdown(CancellationTokenSource hostShutdownSource)
|
||||||
{
|
{
|
||||||
|
Logger.LogInformation("Host process shutting down.");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hostShutdownSource.Cancel();
|
hostShutdownSource.Cancel();
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ namespace DeploymentHelpers
|
||||||
{
|
{
|
||||||
private IISApplication _application;
|
private IISApplication _application;
|
||||||
private CancellationTokenSource _hostShutdownToken = new CancellationTokenSource();
|
private CancellationTokenSource _hostShutdownToken = new CancellationTokenSource();
|
||||||
|
private static object _syncObject = new object();
|
||||||
|
|
||||||
public IISDeployer(DeploymentParameters startParameters, ILogger logger)
|
public IISDeployer(DeploymentParameters startParameters, ILogger logger)
|
||||||
: base(startParameters, logger)
|
: base(startParameters, logger)
|
||||||
|
|
@ -46,7 +47,14 @@ namespace DeploymentHelpers
|
||||||
TurnRammFarOnNativeModule();
|
TurnRammFarOnNativeModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
_application.Deploy();
|
lock (_syncObject)
|
||||||
|
{
|
||||||
|
// To prevent modifying the IIS setup concurrently.
|
||||||
|
_application.Deploy();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warm up time for IIS setup.
|
||||||
|
Thread.Sleep(1 * 1000);
|
||||||
Logger.LogInformation("Successfully finished IIS application directory setup.");
|
Logger.LogInformation("Successfully finished IIS application directory setup.");
|
||||||
|
|
||||||
return new DeploymentResult
|
return new DeploymentResult
|
||||||
|
|
@ -54,7 +62,7 @@ namespace DeploymentHelpers
|
||||||
WebRootLocation = DeploymentParameters.ApplicationPath,
|
WebRootLocation = DeploymentParameters.ApplicationPath,
|
||||||
DeploymentParameters = DeploymentParameters,
|
DeploymentParameters = DeploymentParameters,
|
||||||
// Accomodate the vdir name.
|
// Accomodate the vdir name.
|
||||||
ApplicationBaseUri = new UriBuilder(Uri.UriSchemeHttp, "localhost", _application.Port, _application.VirtualDirectoryName).Uri.AbsoluteUri + "/",
|
ApplicationBaseUri = new UriBuilder(Uri.UriSchemeHttp, "localhost", IISApplication.Port, _application.VirtualDirectoryName).Uri.AbsoluteUri + "/",
|
||||||
HostShutdownToken = _hostShutdownToken.Token
|
HostShutdownToken = _hostShutdownToken.Token
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -89,8 +97,12 @@ namespace DeploymentHelpers
|
||||||
{
|
{
|
||||||
if (_application != null)
|
if (_application != null)
|
||||||
{
|
{
|
||||||
_application.StopAndDeleteAppPool();
|
lock (_syncObject)
|
||||||
Logger.LogError("Application pool was shutdown successfully.");
|
{
|
||||||
|
// Sequentialize IIS operations.
|
||||||
|
_application.StopAndDeleteAppPool();
|
||||||
|
}
|
||||||
|
|
||||||
TriggerHostShutdown(_hostShutdownToken);
|
TriggerHostShutdown(_hostShutdownToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,17 +114,21 @@ namespace DeploymentHelpers
|
||||||
|
|
||||||
private class IISApplication
|
private class IISApplication
|
||||||
{
|
{
|
||||||
private const string WEBSITE_NAME = "TestWebSite";
|
private const string WEBSITE_NAME = "ASPNETTESTRUNS";
|
||||||
private const string NATIVE_MODULE_MANAGED_RUNTIME_VERSION = "vCoreFX";
|
private const string NATIVE_MODULE_MANAGED_RUNTIME_VERSION = "vCoreFX";
|
||||||
|
|
||||||
private readonly ServerManager _serverManager = new ServerManager();
|
private readonly ServerManager _serverManager = new ServerManager();
|
||||||
private readonly DeploymentParameters _startParameters;
|
private readonly DeploymentParameters _deploymentParameters;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private ApplicationPool _applicationPool;
|
private ApplicationPool _applicationPool;
|
||||||
private Application _application;
|
private Application _application;
|
||||||
|
private Site _website;
|
||||||
|
|
||||||
public string VirtualDirectoryName { get; set; }
|
public string VirtualDirectoryName { get; set; }
|
||||||
|
|
||||||
|
// Always create website with the same port.
|
||||||
|
public const int Port = 5100;
|
||||||
|
|
||||||
public string WebSiteRootFolder
|
public string WebSiteRootFolder
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -120,34 +136,25 @@ namespace DeploymentHelpers
|
||||||
return Path.Combine(
|
return Path.Combine(
|
||||||
Environment.GetEnvironmentVariable("SystemDrive") + @"\",
|
Environment.GetEnvironmentVariable("SystemDrive") + @"\",
|
||||||
"inetpub",
|
"inetpub",
|
||||||
"TestWebSite");
|
WEBSITE_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Port
|
public IISApplication(DeploymentParameters deploymentParameters, ILogger logger)
|
||||||
{
|
{
|
||||||
get
|
_deploymentParameters = deploymentParameters;
|
||||||
{
|
|
||||||
return new Uri(_startParameters.ApplicationBaseUriHint).Port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IISApplication(DeploymentParameters startParameters, ILogger logger)
|
|
||||||
{
|
|
||||||
_startParameters = startParameters;
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deploy()
|
public void Deploy()
|
||||||
{
|
{
|
||||||
VirtualDirectoryName = new DirectoryInfo(_startParameters.ApplicationPath).Parent.Name;
|
VirtualDirectoryName = new DirectoryInfo(_deploymentParameters.ApplicationPath).Parent.Name;
|
||||||
_applicationPool = CreateAppPool(VirtualDirectoryName);
|
_applicationPool = CreateAppPool(VirtualDirectoryName);
|
||||||
_application = Website.Applications.Add("/" + VirtualDirectoryName, _startParameters.ApplicationPath);
|
_application = Website.Applications.Add("/" + VirtualDirectoryName, _deploymentParameters.ApplicationPath);
|
||||||
_application.ApplicationPoolName = _applicationPool.Name;
|
_application.ApplicationPoolName = _applicationPool.Name;
|
||||||
_serverManager.CommitChanges();
|
_serverManager.CommitChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Site _website;
|
|
||||||
private Site Website
|
private Site Website
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -165,24 +172,25 @@ namespace DeploymentHelpers
|
||||||
private ApplicationPool CreateAppPool(string appPoolName)
|
private ApplicationPool CreateAppPool(string appPoolName)
|
||||||
{
|
{
|
||||||
var applicationPool = _serverManager.ApplicationPools.Add(appPoolName);
|
var applicationPool = _serverManager.ApplicationPools.Add(appPoolName);
|
||||||
if (_startParameters.ServerType == ServerType.IISNativeModule)
|
if (_deploymentParameters.ServerType == ServerType.IISNativeModule)
|
||||||
{
|
{
|
||||||
// Not assigning a runtime version will choose v4.0 default.
|
// Not assigning a runtime version will choose v4.0 default.
|
||||||
applicationPool.ManagedRuntimeVersion = NATIVE_MODULE_MANAGED_RUNTIME_VERSION;
|
applicationPool.ManagedRuntimeVersion = NATIVE_MODULE_MANAGED_RUNTIME_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationPool.Enable32BitAppOnWin64 = (_startParameters.RuntimeArchitecture == RuntimeArchitecture.x86);
|
applicationPool.Enable32BitAppOnWin64 = (_deploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86);
|
||||||
_logger.LogInformation("Created {bit} application pool '{name}' with runtime version '{runtime}'.",
|
_logger.LogInformation("Created {bit} application pool '{name}' with runtime version {runtime}.",
|
||||||
_startParameters.RuntimeArchitecture, applicationPool.Name,
|
_deploymentParameters.RuntimeArchitecture, applicationPool.Name,
|
||||||
applicationPool.ManagedRuntimeVersion ?? "default");
|
string.IsNullOrEmpty(applicationPool.ManagedRuntimeVersion) ? "that is default" : applicationPool.ManagedRuntimeVersion);
|
||||||
return applicationPool;
|
return applicationPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopAndDeleteAppPool()
|
public void StopAndDeleteAppPool()
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Stopping application pool '{name}' and deleting application.", _applicationPool.Name);
|
||||||
|
|
||||||
if (_applicationPool != null)
|
if (_applicationPool != null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Stopping application pool '{name}' and deleting application.", _applicationPool.Name);
|
|
||||||
_applicationPool.Stop();
|
_applicationPool.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue