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