1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed: Relax SingleInstancePolicy when using a custom data directory Fixes #1765 (#1782)

This commit is contained in:
Richard Schwab 2017-07-16 15:08:16 +02:00 committed by Leonardo Galli
parent 964c18b236
commit b82f2376a7
2 changed files with 18 additions and 5 deletions

View File

@ -88,11 +88,15 @@ private static void EnsureSingleInstance(bool isService, IStartupContext startup
{
var instancePolicy = _container.Resolve<ISingleInstancePolicy>();
if (isService)
if (startupContext.Flags.Contains(StartupContext.TERMINATE))
{
instancePolicy.KillAllOtherInstance();
}
else if (startupContext.Flags.Contains(StartupContext.TERMINATE))
else if (startupContext.Args.ContainsKey(StartupContext.APPDATA))
{
instancePolicy.WarnIfAlreadyRunning();
}
else if (isService)
{
instancePolicy.KillAllOtherInstance();
}

View File

@ -10,6 +10,7 @@ public interface ISingleInstancePolicy
{
void PreventStartIfAlreadyRunning();
void KillAllOtherInstance();
void WarnIfAlreadyRunning();
}
public class SingleInstancePolicy : ISingleInstancePolicy
@ -45,6 +46,14 @@ public void KillAllOtherInstance()
}
}
public void WarnIfAlreadyRunning()
{
if (IsAlreadyRunning())
{
_logger.Debug("Another instance of Radarr is already running.");
}
}
private bool IsAlreadyRunning()
{
return GetOtherNzbDroneProcessIds().Any();
@ -64,14 +73,14 @@ private List<int> GetOtherNzbDroneProcessIds()
if (otherProcesses.Any())
{
_logger.Info("{0} instance(s) of Sonarr are running", otherProcesses.Count);
_logger.Info("{0} instance(s) of Radarr are running", otherProcesses.Count);
}
return otherProcesses;
}
catch (Exception ex)
{
_logger.Warn(ex, "Failed to check for multiple instances of Sonarr.");
_logger.Warn(ex, "Failed to check for multiple instances of Radarr.");
return new List<int>();
}
}