mirror of https://github.com/lidarr/Lidarr
Update provider now closes all orphaned IISExpress instances before update.
This commit is contained in:
parent
115b06821e
commit
d73853f08b
|
@ -32,6 +32,7 @@ namespace NzbDrone.Common.Test
|
||||||
public void Kill_should_not_fail_on_invalid_process_is(int processId)
|
public void Kill_should_not_fail_on_invalid_process_is(int processId)
|
||||||
{
|
{
|
||||||
_processProvider.Kill(processId);
|
_processProvider.Kill(processId);
|
||||||
|
ExceptionVerification.ExcpectedWarns(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
using System;
|
using System.Linq;
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using NzbDrone.Common;
|
|
||||||
|
|
||||||
namespace NzbDrone.Providers
|
namespace NzbDrone.Common
|
||||||
{
|
{
|
||||||
public class IISProvider
|
public class IISProvider
|
||||||
{
|
{
|
||||||
|
@ -84,7 +84,17 @@ namespace NzbDrone.Providers
|
||||||
IISLogger.Error(e.Data);
|
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);
|
_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)
|
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")
|
e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called") || e.Data == "iisexpress")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//if (e.Data.Contains(" NzbDrone."))
|
Console.WriteLine(e.Data);
|
||||||
{
|
|
||||||
Console.WriteLine(e.Data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
IISLogger.Trace(e.Data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -52,6 +52,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ConfigFileProvider.cs" />
|
<Compile Include="ConfigFileProvider.cs" />
|
||||||
<Compile Include="ConsoleProvider.cs" />
|
<Compile Include="ConsoleProvider.cs" />
|
||||||
|
<Compile Include="IISProvider.cs" />
|
||||||
<Compile Include="Model\AuthenticationType.cs" />
|
<Compile Include="Model\AuthenticationType.cs" />
|
||||||
<Compile Include="PathExtentions.cs" />
|
<Compile Include="PathExtentions.cs" />
|
||||||
<Compile Include="DiskProvider.cs" />
|
<Compile Include="DiskProvider.cs" />
|
||||||
|
|
|
@ -46,18 +46,21 @@ namespace NzbDrone.Common
|
||||||
|
|
||||||
public virtual void Kill(int processId)
|
public virtual void Kill(int processId)
|
||||||
{
|
{
|
||||||
if (processId == 0) return;
|
if (processId == 0 || !Process.GetProcesses().Any(p => p.Id == processId))
|
||||||
if (!Process.GetProcesses().Any(p => p.Id == processId)) return;
|
{
|
||||||
|
Logger.Warn("Cannot find process with id: {0}", processId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var process = Process.GetProcessById(processId);
|
var process = Process.GetProcessById(processId);
|
||||||
|
|
||||||
if (!process.HasExited)
|
if (!process.HasExited)
|
||||||
{
|
{
|
||||||
Logger.Info("[{0}]Killing process", process.Id);
|
Logger.Info("[{0}]: Killing process", process.Id);
|
||||||
process.Kill();
|
process.Kill();
|
||||||
Logger.Info("[{0}]Waiting for exit", process.Id);
|
Logger.Info("[{0}]: Waiting for exit", process.Id);
|
||||||
process.WaitForExit();
|
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
|
StartPath = process.MainModule.FileName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -117,6 +117,15 @@ namespace NzbDrone.Update.Test
|
||||||
Mocker.GetMock<ProcessProvider>().Verify(c => c.Kill(It.IsAny<int>()), Times.Never());
|
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]
|
[Test]
|
||||||
public void should_create_backup_of_current_installation()
|
public void should_create_backup_of_current_installation()
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,8 +36,9 @@ namespace NzbDrone.Update
|
||||||
var processProvider = new ProcessProvider();
|
var processProvider = new ProcessProvider();
|
||||||
var serviceProvider = new ServiceProvider();
|
var serviceProvider = new ServiceProvider();
|
||||||
var diskProvider = new DiskProvider();
|
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);
|
new Program(updateProvider, processProvider).Start(args);
|
||||||
}
|
}
|
||||||
|
@ -58,12 +59,12 @@ namespace NzbDrone.Update
|
||||||
fileTarget.ConcurrentWrites = false;
|
fileTarget.ConcurrentWrites = false;
|
||||||
fileTarget.DeleteOldFileOnStartup = true;
|
fileTarget.DeleteOldFileOnStartup = true;
|
||||||
fileTarget.FileName = "upgrade.log";
|
fileTarget.FileName = "upgrade.log";
|
||||||
fileTarget.KeepFileOpen =false;
|
fileTarget.KeepFileOpen = false;
|
||||||
|
|
||||||
fileTarget.Layout = "${logger}: ${message} ${exception}";
|
fileTarget.Layout = "${logger}: ${message} ${exception}";
|
||||||
LogManager.Configuration.AddTarget(fileTarget.GetType().Name, fileTarget);
|
LogManager.Configuration.AddTarget(fileTarget.GetType().Name, fileTarget);
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget));
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget));
|
||||||
|
|
||||||
LogConfiguration.Reload();
|
LogConfiguration.Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,15 +13,17 @@ namespace NzbDrone.Update.Providers
|
||||||
private readonly ServiceProvider _serviceProvider;
|
private readonly ServiceProvider _serviceProvider;
|
||||||
private readonly ProcessProvider _processProvider;
|
private readonly ProcessProvider _processProvider;
|
||||||
private readonly EnviromentProvider _enviromentProvider;
|
private readonly EnviromentProvider _enviromentProvider;
|
||||||
|
private readonly IISProvider _iisProvider;
|
||||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public UpdateProvider(DiskProvider diskProvider, ServiceProvider serviceProvider,
|
public UpdateProvider(DiskProvider diskProvider, ServiceProvider serviceProvider,
|
||||||
ProcessProvider processProvider, EnviromentProvider enviromentProvider)
|
ProcessProvider processProvider, EnviromentProvider enviromentProvider, IISProvider iisProvider)
|
||||||
{
|
{
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_processProvider = processProvider;
|
_processProvider = processProvider;
|
||||||
_enviromentProvider = enviromentProvider;
|
_enviromentProvider = enviromentProvider;
|
||||||
|
_iisProvider = iisProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateProvider()
|
public UpdateProvider()
|
||||||
|
@ -50,14 +52,14 @@ namespace NzbDrone.Update.Providers
|
||||||
bool isService = false;
|
bool isService = false;
|
||||||
|
|
||||||
logger.Info("Stopping all running services");
|
logger.Info("Stopping all running services");
|
||||||
|
|
||||||
if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)
|
if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)
|
||||||
&& _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
&& _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
||||||
{
|
{
|
||||||
isService = true;
|
isService = true;
|
||||||
_serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
_serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("Killing all running processes");
|
logger.Info("Killing all running processes");
|
||||||
var processes = _processProvider.GetProcessByName(ProcessProvider.NzbDroneProccessName);
|
var processes = _processProvider.GetProcessByName(ProcessProvider.NzbDroneProccessName);
|
||||||
foreach (var processInfo in processes)
|
foreach (var processInfo in processes)
|
||||||
|
@ -65,6 +67,9 @@ namespace NzbDrone.Update.Providers
|
||||||
_processProvider.Kill(processInfo.Id);
|
_processProvider.Kill(processInfo.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Info("Killing all orphan IISExpress processes");
|
||||||
|
_iisProvider.StopServer();
|
||||||
|
|
||||||
logger.Info("Creating backup of existing installation");
|
logger.Info("Creating backup of existing installation");
|
||||||
_diskProvider.CopyDirectory(targetFolder, _enviromentProvider.GetUpdateBackUpFolder());
|
_diskProvider.CopyDirectory(targetFolder, _enviromentProvider.GetUpdateBackUpFolder());
|
||||||
|
|
||||||
|
@ -79,7 +84,7 @@ namespace NzbDrone.Update.Providers
|
||||||
{
|
{
|
||||||
RollBack(targetFolder);
|
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]);
|
logger.Trace("Key: {0}, Value: {1}", key, e.Data[key]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,6 @@
|
||||||
<Compile Include="Model\ApplicationMode.cs" />
|
<Compile Include="Model\ApplicationMode.cs" />
|
||||||
<Compile Include="Providers\DebuggerProvider.cs" />
|
<Compile Include="Providers\DebuggerProvider.cs" />
|
||||||
<Compile Include="ProcessAttacher.cs" />
|
<Compile Include="ProcessAttacher.cs" />
|
||||||
<Compile Include="Providers\IISProvider.cs" />
|
|
||||||
<Compile Include="AppMain.cs" />
|
<Compile Include="AppMain.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Providers\MonitoringProvider.cs" />
|
<Compile Include="Providers\MonitoringProvider.cs" />
|
||||||
|
|
Loading…
Reference in New Issue