From d73853f08b49174d88b2085e467c475fa919ae5d Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 20 Nov 2011 17:13:58 -0800 Subject: [PATCH] Update provider now closes all orphaned IISExpress instances before update. --- NzbDrone.Common.Test/ProcessProviderTests.cs | 1 + .../IISProvider.cs | 33 +++++++++---------- NzbDrone.Common/NzbDrone.Common.csproj | 1 + NzbDrone.Common/ProcessProvider.cs | 14 +++++--- .../UpdateProviderStartFixture.cs | 9 +++++ NzbDrone.Update/Program.cs | 9 ++--- NzbDrone.Update/Providers/UpdateProvider.cs | 13 +++++--- NzbDrone/NzbDrone.csproj | 1 - 8 files changed, 49 insertions(+), 32 deletions(-) rename {NzbDrone/Providers => NzbDrone.Common}/IISProvider.cs (93%) diff --git a/NzbDrone.Common.Test/ProcessProviderTests.cs b/NzbDrone.Common.Test/ProcessProviderTests.cs index c62eb1f83..2a9adfed7 100644 --- a/NzbDrone.Common.Test/ProcessProviderTests.cs +++ b/NzbDrone.Common.Test/ProcessProviderTests.cs @@ -32,6 +32,7 @@ namespace NzbDrone.Common.Test public void Kill_should_not_fail_on_invalid_process_is(int processId) { _processProvider.Kill(processId); + ExceptionVerification.ExcpectedWarns(1); } [Test] diff --git a/NzbDrone/Providers/IISProvider.cs b/NzbDrone.Common/IISProvider.cs similarity index 93% rename from NzbDrone/Providers/IISProvider.cs rename to NzbDrone.Common/IISProvider.cs index 04256fd66..86d6df842 100644 --- a/NzbDrone/Providers/IISProvider.cs +++ b/NzbDrone.Common/IISProvider.cs @@ -1,10 +1,10 @@ -using System; +using System.Linq; +using System; using System.Diagnostics; using NLog; using Ninject; -using NzbDrone.Common; -namespace NzbDrone.Providers +namespace NzbDrone.Common { public class IISProvider { @@ -84,7 +84,17 @@ namespace NzbDrone.Providers IISLogger.Error(e.Data); } - public void StopServer() + + public void RestartServer() + { + ServerStarted = false; + Logger.Warn("Attempting to restart server."); + StopServer(); + StartServer(); + } + + + public virtual void StopServer() { _processProvider.Kill(IISProcessId); @@ -104,13 +114,6 @@ namespace NzbDrone.Providers } } - public void RestartServer() - { - ServerStarted = false; - Logger.Warn("Attempting to restart server."); - StopServer(); - StartServer(); - } private void OnOutputDataReceived(object s, DataReceivedEventArgs e) { @@ -118,13 +121,7 @@ namespace NzbDrone.Providers e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called") || e.Data == "iisexpress") return; - //if (e.Data.Contains(" NzbDrone.")) - { - Console.WriteLine(e.Data); - return; - } - - IISLogger.Trace(e.Data); + Console.WriteLine(e.Data); } } diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index a33eee862..e08702976 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -52,6 +52,7 @@ + diff --git a/NzbDrone.Common/ProcessProvider.cs b/NzbDrone.Common/ProcessProvider.cs index 8ed58d95c..348bcdb4d 100644 --- a/NzbDrone.Common/ProcessProvider.cs +++ b/NzbDrone.Common/ProcessProvider.cs @@ -46,18 +46,21 @@ namespace NzbDrone.Common public virtual void Kill(int processId) { - if (processId == 0) return; - if (!Process.GetProcesses().Any(p => p.Id == processId)) return; + if (processId == 0 || !Process.GetProcesses().Any(p => p.Id == processId)) + { + Logger.Warn("Cannot find process with id: {0}", processId); + return; + } var process = Process.GetProcessById(processId); if (!process.HasExited) { - Logger.Info("[{0}]Killing process", process.Id); + Logger.Info("[{0}]: Killing process", process.Id); process.Kill(); - Logger.Info("[{0}]Waiting for exit", process.Id); + Logger.Info("[{0}]: Waiting for exit", process.Id); process.WaitForExit(); - Logger.Info("[{0}]Process terminated successfully", process.Id); + Logger.Info("[{0}]: Process terminated successfully", process.Id); } } @@ -84,5 +87,6 @@ namespace NzbDrone.Common StartPath = process.MainModule.FileName }; } + } } \ No newline at end of file diff --git a/NzbDrone.Update.Test/UpdateProviderStartFixture.cs b/NzbDrone.Update.Test/UpdateProviderStartFixture.cs index 7cfd0d73b..9faf57e1c 100644 --- a/NzbDrone.Update.Test/UpdateProviderStartFixture.cs +++ b/NzbDrone.Update.Test/UpdateProviderStartFixture.cs @@ -117,6 +117,15 @@ namespace NzbDrone.Update.Test Mocker.GetMock().Verify(c => c.Kill(It.IsAny()), Times.Never()); } + [Test] + public void should_stop_orphan_iisexpress_instances() + { + Mocker.Resolve().Start(TARGET_FOLDER); + + //Assert + Mocker.GetMock().Verify(c => c.StopServer(), Times.Once()); + } + [Test] public void should_create_backup_of_current_installation() { diff --git a/NzbDrone.Update/Program.cs b/NzbDrone.Update/Program.cs index bddb8221e..e2439b2ea 100644 --- a/NzbDrone.Update/Program.cs +++ b/NzbDrone.Update/Program.cs @@ -36,8 +36,9 @@ namespace NzbDrone.Update var processProvider = new ProcessProvider(); var serviceProvider = new ServiceProvider(); var diskProvider = new DiskProvider(); + var iisProvider = new IISProvider(); - var updateProvider = new UpdateProvider(diskProvider, serviceProvider, processProvider, enviromentProvider); + var updateProvider = new UpdateProvider(diskProvider, serviceProvider, processProvider, enviromentProvider, iisProvider); new Program(updateProvider, processProvider).Start(args); } @@ -58,12 +59,12 @@ namespace NzbDrone.Update fileTarget.ConcurrentWrites = false; fileTarget.DeleteOldFileOnStartup = true; fileTarget.FileName = "upgrade.log"; - fileTarget.KeepFileOpen =false; - + fileTarget.KeepFileOpen = false; + fileTarget.Layout = "${logger}: ${message} ${exception}"; LogManager.Configuration.AddTarget(fileTarget.GetType().Name, fileTarget); LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget)); - + LogConfiguration.Reload(); } diff --git a/NzbDrone.Update/Providers/UpdateProvider.cs b/NzbDrone.Update/Providers/UpdateProvider.cs index 75d8f6ffb..f34c91c46 100644 --- a/NzbDrone.Update/Providers/UpdateProvider.cs +++ b/NzbDrone.Update/Providers/UpdateProvider.cs @@ -13,15 +13,17 @@ namespace NzbDrone.Update.Providers private readonly ServiceProvider _serviceProvider; private readonly ProcessProvider _processProvider; private readonly EnviromentProvider _enviromentProvider; + private readonly IISProvider _iisProvider; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); public UpdateProvider(DiskProvider diskProvider, ServiceProvider serviceProvider, - ProcessProvider processProvider, EnviromentProvider enviromentProvider) + ProcessProvider processProvider, EnviromentProvider enviromentProvider, IISProvider iisProvider) { _diskProvider = diskProvider; _serviceProvider = serviceProvider; _processProvider = processProvider; _enviromentProvider = enviromentProvider; + _iisProvider = iisProvider; } public UpdateProvider() @@ -50,14 +52,14 @@ namespace NzbDrone.Update.Providers bool isService = false; logger.Info("Stopping all running services"); - + if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) && _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME)) { isService = true; _serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME); } - + logger.Info("Killing all running processes"); var processes = _processProvider.GetProcessByName(ProcessProvider.NzbDroneProccessName); foreach (var processInfo in processes) @@ -65,6 +67,9 @@ namespace NzbDrone.Update.Providers _processProvider.Kill(processInfo.Id); } + logger.Info("Killing all orphan IISExpress processes"); + _iisProvider.StopServer(); + logger.Info("Creating backup of existing installation"); _diskProvider.CopyDirectory(targetFolder, _enviromentProvider.GetUpdateBackUpFolder()); @@ -79,7 +84,7 @@ namespace NzbDrone.Update.Providers { RollBack(targetFolder); - foreach(var key in e.Data.Keys) + foreach (var key in e.Data.Keys) { logger.Trace("Key: {0}, Value: {1}", key, e.Data[key]); } diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index 2b221c2d3..41233f488 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -87,7 +87,6 @@ -