mirror of https://github.com/lidarr/Lidarr
Fixed ping for servers with windows auth enabled.
This commit is contained in:
parent
5ecbdd3e64
commit
786e38763a
|
@ -29,7 +29,7 @@ namespace NzbDrone.App.Test
|
||||||
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
subject.EnsurePriority(null, null);
|
subject.EnsurePriority(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Security.Principal;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
|
@ -14,28 +15,23 @@ namespace NzbDrone.Common
|
||||||
|
|
||||||
public virtual string DownloadString(string address)
|
public virtual string DownloadString(string address)
|
||||||
{
|
{
|
||||||
try
|
return DownloadString(address, null);
|
||||||
{
|
|
||||||
return new WebClient().DownloadString(address);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.TraceException(ex.Message, ex);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual string DownloadString(string address, string username, string password)
|
public virtual string DownloadString(string address, string username, string password)
|
||||||
|
{
|
||||||
|
return DownloadString(address, new NetworkCredential(username, password));
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string DownloadString(string address, ICredentials identity)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var webClient = new WebClient();
|
var client = new WebClient { Credentials = identity };
|
||||||
webClient.Credentials = new NetworkCredential(username, password);
|
return client.DownloadString(address);
|
||||||
return webClient.DownloadString(address);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.Warn("Failed to get response from: {0}", address);
|
|
||||||
logger.TraceException(ex.Message, ex);
|
logger.TraceException(ex.Message, ex);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
@ -113,5 +109,7 @@ namespace NzbDrone.Common
|
||||||
|
|
||||||
return responseFromServer.Replace(" ", " ");
|
return responseFromServer.Replace(" ", " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -76,8 +76,6 @@
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.ServiceProcess" />
|
<Reference Include="System.ServiceProcess" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
|
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Net;
|
||||||
using System.Runtime.Remoting;
|
using System.Runtime.Remoting;
|
||||||
using System.Timers;
|
using System.Threading;
|
||||||
using Exceptioneer.WindowsFormsClient;
|
using Exceptioneer.WindowsFormsClient;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
|
@ -12,7 +13,7 @@ namespace NzbDrone.Providers
|
||||||
{
|
{
|
||||||
public class MonitoringProvider
|
public class MonitoringProvider
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.GetLogger("Host.MonitoringProvider");
|
private static readonly Logger logger = LogManager.GetLogger("Host.MonitoringProvider");
|
||||||
|
|
||||||
private readonly IISProvider _iisProvider;
|
private readonly IISProvider _iisProvider;
|
||||||
private readonly ProcessProvider _processProvider;
|
private readonly ProcessProvider _processProvider;
|
||||||
|
@ -21,6 +22,7 @@ namespace NzbDrone.Providers
|
||||||
|
|
||||||
private int _pingFailCounter;
|
private int _pingFailCounter;
|
||||||
private Timer _pingTimer;
|
private Timer _pingTimer;
|
||||||
|
private Timer _processPriorityCheckTimer;
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
public MonitoringProvider(ProcessProvider processProvider, IISProvider iisProvider,
|
public MonitoringProvider(ProcessProvider processProvider, IISProvider iisProvider,
|
||||||
|
@ -42,18 +44,16 @@ namespace NzbDrone.Providers
|
||||||
|
|
||||||
AppDomain.CurrentDomain.ProcessExit += ProgramExited;
|
AppDomain.CurrentDomain.ProcessExit += ProgramExited;
|
||||||
AppDomain.CurrentDomain.DomainUnload += ProgramExited;
|
AppDomain.CurrentDomain.DomainUnload += ProgramExited;
|
||||||
|
|
||||||
|
_processPriorityCheckTimer = new Timer(EnsurePriority);
|
||||||
|
_processPriorityCheckTimer.Change(TimeSpan.FromSeconds(15), TimeSpan.FromMinutes(30));
|
||||||
|
|
||||||
var prioCheckTimer = new Timer(5000);
|
_pingTimer = new Timer(PingServer);
|
||||||
prioCheckTimer.Elapsed += EnsurePriority;
|
_pingTimer.Change(TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(1));
|
||||||
prioCheckTimer.Enabled = true;
|
|
||||||
|
|
||||||
_pingTimer = new Timer(180000) { AutoReset = true };
|
|
||||||
_pingTimer.Elapsed += (PingServer);
|
|
||||||
_pingTimer.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual void EnsurePriority(object sender, ElapsedEventArgs e)
|
public virtual void EnsurePriority(object sender)
|
||||||
{
|
{
|
||||||
var currentProcess = _processProvider.GetCurrentProcess();
|
var currentProcess = _processProvider.GetCurrentProcess();
|
||||||
if (currentProcess.Priority != ProcessPriorityClass.Normal)
|
if (currentProcess.Priority != ProcessPriorityClass.Normal)
|
||||||
|
@ -69,14 +69,21 @@ namespace NzbDrone.Providers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void PingServer(object sender, ElapsedEventArgs e)
|
public virtual void PingServer(object sender)
|
||||||
{
|
{
|
||||||
if (!_iisProvider.ServerStarted || _configFileProvider.AuthenticationType == AuthenticationType.Windows) return;
|
if (!_iisProvider.ServerStarted) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_httpProvider.DownloadString(_iisProvider.AppUrl); //This should preload the home page, making the first load alot faster.
|
ICredentials identity = null;
|
||||||
string response = _httpProvider.DownloadString(_iisProvider.AppUrl + "/health");
|
|
||||||
|
if (_configFileProvider.AuthenticationType == AuthenticationType.Windows)
|
||||||
|
{
|
||||||
|
identity = CredentialCache.DefaultCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
_httpProvider.DownloadString(_iisProvider.AppUrl, identity); //This should preload the home page, making the first load faster.
|
||||||
|
string response = _httpProvider.DownloadString(_iisProvider.AppUrl + "/health", identity);
|
||||||
|
|
||||||
if (!response.Contains("OK"))
|
if (!response.Contains("OK"))
|
||||||
{
|
{
|
||||||
|
@ -85,7 +92,7 @@ namespace NzbDrone.Providers
|
||||||
|
|
||||||
if (_pingFailCounter > 0)
|
if (_pingFailCounter > 0)
|
||||||
{
|
{
|
||||||
Logger.Info("Application pool has been successfully recovered.");
|
logger.Info("Application pool has been successfully recovered.");
|
||||||
}
|
}
|
||||||
|
|
||||||
_pingFailCounter = 0;
|
_pingFailCounter = 0;
|
||||||
|
@ -93,7 +100,7 @@ namespace NzbDrone.Providers
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_pingFailCounter++;
|
_pingFailCounter++;
|
||||||
Logger.ErrorException("Application pool is not responding. Count " + _pingFailCounter, ex);
|
logger.ErrorException("Application pool is not responding. Count " + _pingFailCounter, ex);
|
||||||
if (_pingFailCounter > 4)
|
if (_pingFailCounter > 4)
|
||||||
{
|
{
|
||||||
_pingFailCounter = 0;
|
_pingFailCounter = 0;
|
||||||
|
@ -122,7 +129,7 @@ namespace NzbDrone.Providers
|
||||||
}.Submit();
|
}.Submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.FatalException("EPIC FAIL: " + excepion.Message, excepion);
|
logger.FatalException("EPIC FAIL: " + excepion.Message, excepion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue