mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
Cleaned-up NzbDrone.exe
This commit is contained in:
parent
8c7c2ac296
commit
8ec72ed432
@ -27,7 +27,7 @@ internal static string AppUrl
|
|||||||
get { return string.Format("http://localhost:{0}/", Config.Port); }
|
get { return string.Format("http://localhost:{0}/", Config.Port); }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Process StartIIS()
|
internal static Process StartServer()
|
||||||
{
|
{
|
||||||
Logger.Info("Preparing IISExpress Server...");
|
Logger.Info("Preparing IISExpress Server...");
|
||||||
IISProcess = new Process();
|
IISProcess = new Process();
|
||||||
@ -44,9 +44,6 @@ internal static Process StartIIS()
|
|||||||
|
|
||||||
IISProcess.OutputDataReceived += (OnDataReceived);
|
IISProcess.OutputDataReceived += (OnDataReceived);
|
||||||
|
|
||||||
IISProcess.ErrorDataReceived += ((s, e) => IISLogger.Fatal(e.Data));
|
|
||||||
|
|
||||||
|
|
||||||
//Set Variables for the config file.
|
//Set Variables for the config file.
|
||||||
Environment.SetEnvironmentVariable("NZBDRONE_PATH", Config.ProjectRoot);
|
Environment.SetEnvironmentVariable("NZBDRONE_PATH", Config.ProjectRoot);
|
||||||
|
|
||||||
@ -66,59 +63,18 @@ internal static Process StartIIS()
|
|||||||
IISProcess.BeginErrorReadLine();
|
IISProcess.BeginErrorReadLine();
|
||||||
IISProcess.BeginOutputReadLine();
|
IISProcess.BeginOutputReadLine();
|
||||||
|
|
||||||
StartPing();
|
//Start Ping
|
||||||
|
_pingTimer = new Timer(10000) { AutoReset = true };
|
||||||
|
_pingTimer.Elapsed += (Server);
|
||||||
|
_pingTimer.Start();
|
||||||
|
|
||||||
return IISProcess;
|
return IISProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void StartPing()
|
internal static void StopServer()
|
||||||
{
|
|
||||||
_pingTimer = new Timer(10000);
|
|
||||||
_pingTimer.AutoReset = true;
|
|
||||||
_pingTimer.Elapsed += (PingIIS);
|
|
||||||
_pingTimer.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void PingIIS(object sender, ElapsedEventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var webClient = new WebClient();
|
|
||||||
webClient.DownloadString(AppUrl);
|
|
||||||
Logger.Info("Server said hai...");
|
|
||||||
_pingFailCounter = 0;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_pingFailCounter++;
|
|
||||||
Logger.ErrorException("App is not responding. Count " + _pingFailCounter, ex);
|
|
||||||
if (_pingFailCounter > 3)
|
|
||||||
{
|
|
||||||
_pingTimer.Stop();
|
|
||||||
Logger.Warn("Attempting to restart server.");
|
|
||||||
StopIIS();
|
|
||||||
KillOrphaned();
|
|
||||||
StartIIS();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnDataReceived(object s, DataReceivedEventArgs e)
|
|
||||||
{
|
|
||||||
if (e == null || e.Data == null || e.Data.StartsWith("Request started:") ||
|
|
||||||
e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
IISLogger.Trace(e.Data);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void StopIIS()
|
|
||||||
{
|
{
|
||||||
KillProcess(IISProcess);
|
KillProcess(IISProcess);
|
||||||
}
|
|
||||||
|
|
||||||
internal static void KillOrphaned()
|
|
||||||
{
|
|
||||||
Logger.Info("Finding orphaned IIS Processes.");
|
Logger.Info("Finding orphaned IIS Processes.");
|
||||||
foreach (var process in Process.GetProcessesByName("IISExpress"))
|
foreach (var process in Process.GetProcessesByName("IISExpress"))
|
||||||
{
|
{
|
||||||
@ -136,16 +92,40 @@ internal static void KillOrphaned()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void KillProcess(Process process)
|
private static void RestartServer()
|
||||||
{
|
{
|
||||||
if (process != null && !process.HasExited)
|
_pingTimer.Stop();
|
||||||
|
Logger.Warn("Attempting to restart server.");
|
||||||
|
StopServer();
|
||||||
|
StartServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Server(object sender, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Logger.Info("[{0}]Killing process", process.Id);
|
new WebClient().DownloadString(AppUrl);
|
||||||
process.Kill();
|
Logger.Info("Server said hai...");
|
||||||
Logger.Info("[{0}]Waiting for exit", process.Id);
|
_pingFailCounter = 0;
|
||||||
process.WaitForExit();
|
|
||||||
Logger.Info("[{0}]Process terminated successfully", process.Id);
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_pingFailCounter++;
|
||||||
|
Logger.ErrorException("App is not responding. Count " + _pingFailCounter, ex);
|
||||||
|
if (_pingFailCounter > 2)
|
||||||
|
{
|
||||||
|
RestartServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnDataReceived(object s, DataReceivedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e == null || e.Data == null || e.Data.StartsWith("Request started:") ||
|
||||||
|
e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
IISLogger.Trace(e.Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateIISConfig()
|
private static void UpdateIISConfig()
|
||||||
@ -170,6 +150,18 @@ private static void UpdateIISConfig()
|
|||||||
configXml.Save(configPath);
|
configXml.Save(configPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void KillProcess(Process process)
|
||||||
|
{
|
||||||
|
if (process != null && !process.HasExited)
|
||||||
|
{
|
||||||
|
Logger.Info("[{0}]Killing process", process.Id);
|
||||||
|
process.Kill();
|
||||||
|
Logger.Info("[{0}]Waiting for exit", process.Id);
|
||||||
|
process.WaitForExit();
|
||||||
|
Logger.Info("[{0}]Process terminated successfully", process.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static string CleanPath(string path)
|
private static string CleanPath(string path)
|
||||||
{
|
{
|
||||||
return path.ToLower().Replace("\\", "").Replace("//", "//");
|
return path.ToLower().Replace("\\", "").Replace("//", "//");
|
||||||
|
@ -27,8 +27,8 @@ private static void Main()
|
|||||||
|
|
||||||
Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", Config.ProjectRoot);
|
Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", Config.ProjectRoot);
|
||||||
|
|
||||||
IISController.KillOrphaned();
|
IISController.StopServer();
|
||||||
IISController.StartIIS();
|
IISController.StartServer();
|
||||||
|
|
||||||
Process.Start(IISController.AppUrl);
|
Process.Start(IISController.AppUrl);
|
||||||
|
|
||||||
@ -52,10 +52,6 @@ private static void Main()
|
|||||||
AppDomainException(e);
|
AppDomainException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.Write("Press Enter At Any Time To Exit...");
|
|
||||||
|
|
||||||
Console.ReadLine();
|
|
||||||
IISController.StopIIS();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -71,12 +67,12 @@ private static void AppDomainException(object excepion)
|
|||||||
CurrentException = excepion as Exception
|
CurrentException = excepion as Exception
|
||||||
}.Submit();
|
}.Submit();
|
||||||
|
|
||||||
IISController.StopIIS();
|
IISController.StopServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ProgramExited(object sender, EventArgs e)
|
private static void ProgramExited(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
IISController.StopIIS();
|
IISController.StopServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user