Update provider now closes all orphaned IISExpress instances before update.

This commit is contained in:
kay.one 2011-11-20 17:13:58 -08:00
parent 115b06821e
commit d73853f08b
8 changed files with 49 additions and 32 deletions

View File

@ -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]

View File

@ -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);
}
}

View File

@ -52,6 +52,7 @@
<ItemGroup>
<Compile Include="ConfigFileProvider.cs" />
<Compile Include="ConsoleProvider.cs" />
<Compile Include="IISProvider.cs" />
<Compile Include="Model\AuthenticationType.cs" />
<Compile Include="PathExtentions.cs" />
<Compile Include="DiskProvider.cs" />

View File

@ -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
};
}
}
}

View File

@ -117,6 +117,15 @@ namespace NzbDrone.Update.Test
Mocker.GetMock<ProcessProvider>().Verify(c => c.Kill(It.IsAny<int>()), Times.Never());
}
[Test]
public void should_stop_orphan_iisexpress_instances()
{
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
//Assert
Mocker.GetMock<IISProvider>().Verify(c => c.StopServer(), Times.Once());
}
[Test]
public void should_create_backup_of_current_installation()
{

View File

@ -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();
}

View File

@ -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]);
}

View File

@ -87,7 +87,6 @@
<Compile Include="Model\ApplicationMode.cs" />
<Compile Include="Providers\DebuggerProvider.cs" />
<Compile Include="ProcessAttacher.cs" />
<Compile Include="Providers\IISProvider.cs" />
<Compile Include="AppMain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\MonitoringProvider.cs" />