mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-30 07:22:35 +01:00
Fixed an upgrade/service bug where it would try to stop an already stopped service.
This commit is contained in:
parent
9dbc97223f
commit
e35a4bf8ac
@ -67,7 +67,7 @@
|
||||
<Compile Include="DiskProviderTests.cs" />
|
||||
<Compile Include="EnviromentProviderTest.cs" />
|
||||
<Compile Include="ProcessProviderTests.cs" />
|
||||
<Compile Include="ServiceControllerTests.cs" />
|
||||
<Compile Include="ServiceProviderTests.cs" />
|
||||
<Compile Include="WebClientTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -8,10 +8,10 @@ using NzbDrone.Test.Common;
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class ServiceControllerTests:TestBase
|
||||
public class ServiceProviderTests : TestBase
|
||||
{
|
||||
private const string ALWAYS_INSTALLED_SERVICE = "SCardSvr"; //Smart Card
|
||||
private const string TEMP_SERVICE_NAME = "NzbDrone_Nunit"; //Smart Card
|
||||
private const string TEMP_SERVICE_NAME = "NzbDrone_Nunit";
|
||||
private ServiceProvider serviceProvider;
|
||||
|
||||
|
||||
@ -91,5 +91,21 @@ namespace NzbDrone.Common.Test
|
||||
serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||
.Should().Be(ServiceControllerStatus.Stopped);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Should_log_warn_if_on_stop_if_service_is_already_stopped()
|
||||
{
|
||||
serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||
.Should().NotBe(ServiceControllerStatus.Running);
|
||||
|
||||
//Act
|
||||
serviceProvider.Stop(ALWAYS_INSTALLED_SERVICE);
|
||||
|
||||
//Assert
|
||||
serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||
.Should().Be(ServiceControllerStatus.Stopped);
|
||||
|
||||
ExceptionVerification.ExcpectedWarns(1);
|
||||
}
|
||||
}
|
||||
}
|
@ -100,17 +100,24 @@ namespace NzbDrone.Common
|
||||
|
||||
Logger.Info("Service is currently {0}", service.Status);
|
||||
|
||||
service.Stop();
|
||||
service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(60));
|
||||
|
||||
service.Refresh();
|
||||
if (service.Status == ServiceControllerStatus.Stopped)
|
||||
if (service.Status != ServiceControllerStatus.Stopped)
|
||||
{
|
||||
Logger.Info("{0} has stopped successfully.");
|
||||
service.Stop();
|
||||
service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(60));
|
||||
|
||||
service.Refresh();
|
||||
if (service.Status == ServiceControllerStatus.Stopped)
|
||||
{
|
||||
Logger.Info("{0} has stopped successfully.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error("Service stop request has timed out. {0}", service.Status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error("Service stop request has timed out. {0}", service.Status);
|
||||
Logger.Warn("Service {0} is already in stopped state.", service.ServiceName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,10 @@ namespace NzbDrone.Update.Test
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_stop_nzbdrone_service_if_installed()
|
||||
public void should_stop_nzbdrone_service_if_installed_and_running()
|
||||
{
|
||||
WithInstalledService();
|
||||
WithServiceRunning(true);
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
||||
@ -62,6 +63,19 @@ namespace NzbDrone.Update.Test
|
||||
Mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_stop_nzbdrone_service_if_installed_but_not_running()
|
||||
{
|
||||
WithInstalledService();
|
||||
WithServiceRunning(false);
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
|
||||
|
||||
//Assert
|
||||
Mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_stop_nzbdrone_service_if_service_isnt_installed()
|
||||
{
|
||||
|
@ -49,15 +49,14 @@ namespace NzbDrone.Update.Providers
|
||||
bool isService = false;
|
||||
|
||||
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))
|
||||
{
|
||||
if (_serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
||||
{
|
||||
isService = true;
|
||||
}
|
||||
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)
|
||||
|
@ -33,6 +33,7 @@ namespace NzbDrone
|
||||
{
|
||||
Logger.Info("Application mode: {0}", applicationMode);
|
||||
|
||||
//TODO:move this outside, it should be one of application modes (ApplicationMode.Service?)
|
||||
if (!_enviromentProvider.IsUserInteractive)
|
||||
{
|
||||
_serviceProvider.Run(_applicationServer);
|
||||
|
Loading…
Reference in New Issue
Block a user