Stabilizing IIS helpers.
This commit is contained in:
parent
9eca47b388
commit
c44e65c27f
|
|
@ -195,6 +195,7 @@ namespace DeploymentHelpers
|
|||
|
||||
protected void TriggerHostShutdown(CancellationTokenSource hostShutdownSource)
|
||||
{
|
||||
Logger.LogInformation("Host process shutting down.");
|
||||
try
|
||||
{
|
||||
hostShutdownSource.Cancel();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace DeploymentHelpers
|
|||
{
|
||||
private IISApplication _application;
|
||||
private CancellationTokenSource _hostShutdownToken = new CancellationTokenSource();
|
||||
private static object _syncObject = new object();
|
||||
|
||||
public IISDeployer(DeploymentParameters startParameters, ILogger logger)
|
||||
: base(startParameters, logger)
|
||||
|
|
@ -46,7 +47,14 @@ namespace DeploymentHelpers
|
|||
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.");
|
||||
|
||||
return new DeploymentResult
|
||||
|
|
@ -54,7 +62,7 @@ namespace DeploymentHelpers
|
|||
WebRootLocation = DeploymentParameters.ApplicationPath,
|
||||
DeploymentParameters = DeploymentParameters,
|
||||
// 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
|
||||
};
|
||||
}
|
||||
|
|
@ -89,8 +97,12 @@ namespace DeploymentHelpers
|
|||
{
|
||||
if (_application != null)
|
||||
{
|
||||
_application.StopAndDeleteAppPool();
|
||||
Logger.LogError("Application pool was shutdown successfully.");
|
||||
lock (_syncObject)
|
||||
{
|
||||
// Sequentialize IIS operations.
|
||||
_application.StopAndDeleteAppPool();
|
||||
}
|
||||
|
||||
TriggerHostShutdown(_hostShutdownToken);
|
||||
}
|
||||
|
||||
|
|
@ -102,17 +114,21 @@ namespace DeploymentHelpers
|
|||
|
||||
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 readonly ServerManager _serverManager = new ServerManager();
|
||||
private readonly DeploymentParameters _startParameters;
|
||||
private readonly DeploymentParameters _deploymentParameters;
|
||||
private readonly ILogger _logger;
|
||||
private ApplicationPool _applicationPool;
|
||||
private Application _application;
|
||||
private Site _website;
|
||||
|
||||
public string VirtualDirectoryName { get; set; }
|
||||
|
||||
// Always create website with the same port.
|
||||
public const int Port = 5100;
|
||||
|
||||
public string WebSiteRootFolder
|
||||
{
|
||||
get
|
||||
|
|
@ -120,34 +136,25 @@ namespace DeploymentHelpers
|
|||
return Path.Combine(
|
||||
Environment.GetEnvironmentVariable("SystemDrive") + @"\",
|
||||
"inetpub",
|
||||
"TestWebSite");
|
||||
WEBSITE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
public int Port
|
||||
public IISApplication(DeploymentParameters deploymentParameters, ILogger logger)
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Uri(_startParameters.ApplicationBaseUriHint).Port;
|
||||
}
|
||||
}
|
||||
|
||||
public IISApplication(DeploymentParameters startParameters, ILogger logger)
|
||||
{
|
||||
_startParameters = startParameters;
|
||||
_deploymentParameters = deploymentParameters;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Deploy()
|
||||
{
|
||||
VirtualDirectoryName = new DirectoryInfo(_startParameters.ApplicationPath).Parent.Name;
|
||||
VirtualDirectoryName = new DirectoryInfo(_deploymentParameters.ApplicationPath).Parent.Name;
|
||||
_applicationPool = CreateAppPool(VirtualDirectoryName);
|
||||
_application = Website.Applications.Add("/" + VirtualDirectoryName, _startParameters.ApplicationPath);
|
||||
_application = Website.Applications.Add("/" + VirtualDirectoryName, _deploymentParameters.ApplicationPath);
|
||||
_application.ApplicationPoolName = _applicationPool.Name;
|
||||
_serverManager.CommitChanges();
|
||||
}
|
||||
|
||||
private Site _website;
|
||||
private Site Website
|
||||
{
|
||||
get
|
||||
|
|
@ -165,24 +172,25 @@ namespace DeploymentHelpers
|
|||
private ApplicationPool CreateAppPool(string 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.
|
||||
applicationPool.ManagedRuntimeVersion = NATIVE_MODULE_MANAGED_RUNTIME_VERSION;
|
||||
}
|
||||
|
||||
applicationPool.Enable32BitAppOnWin64 = (_startParameters.RuntimeArchitecture == RuntimeArchitecture.x86);
|
||||
_logger.LogInformation("Created {bit} application pool '{name}' with runtime version '{runtime}'.",
|
||||
_startParameters.RuntimeArchitecture, applicationPool.Name,
|
||||
applicationPool.ManagedRuntimeVersion ?? "default");
|
||||
applicationPool.Enable32BitAppOnWin64 = (_deploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86);
|
||||
_logger.LogInformation("Created {bit} application pool '{name}' with runtime version {runtime}.",
|
||||
_deploymentParameters.RuntimeArchitecture, applicationPool.Name,
|
||||
string.IsNullOrEmpty(applicationPool.ManagedRuntimeVersion) ? "that is default" : applicationPool.ManagedRuntimeVersion);
|
||||
return applicationPool;
|
||||
}
|
||||
|
||||
public void StopAndDeleteAppPool()
|
||||
{
|
||||
_logger.LogInformation("Stopping application pool '{name}' and deleting application.", _applicationPool.Name);
|
||||
|
||||
if (_applicationPool != null)
|
||||
{
|
||||
_logger.LogInformation("Stopping application pool '{name}' and deleting application.", _applicationPool.Name);
|
||||
_applicationPool.Stop();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue