|
|
@ -27,7 +27,7 @@ namespace NzbDrone
|
|
|
|
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 @@ namespace NzbDrone
|
|
|
|
|
|
|
|
|
|
|
|
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,25 +63,48 @@ namespace NzbDrone
|
|
|
|
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);
|
|
|
|
KillProcess(IISProcess);
|
|
|
|
_pingTimer.AutoReset = true;
|
|
|
|
|
|
|
|
_pingTimer.Elapsed += (PingIIS);
|
|
|
|
Logger.Info("Finding orphaned IIS Processes.");
|
|
|
|
_pingTimer.Start();
|
|
|
|
foreach (var process in Process.GetProcessesByName("IISExpress"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string processPath = process.MainModule.FileName;
|
|
|
|
|
|
|
|
Logger.Info("[{0}]IIS Process found. Path:{1}", process.Id, processPath);
|
|
|
|
|
|
|
|
if (CleanPath(processPath) == CleanPath(IISExe))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Info("[{0}]Process is considered orphaned.", process.Id);
|
|
|
|
|
|
|
|
KillProcess(process);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Info("[{0}]Process has a different start-up path. skipping.", process.Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void PingIIS(object sender, ElapsedEventArgs e)
|
|
|
|
private static void RestartServer()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_pingTimer.Stop();
|
|
|
|
|
|
|
|
Logger.Warn("Attempting to restart server.");
|
|
|
|
|
|
|
|
StopServer();
|
|
|
|
|
|
|
|
StartServer();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void Server(object sender, ElapsedEventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var webClient = new WebClient();
|
|
|
|
new WebClient().DownloadString(AppUrl);
|
|
|
|
webClient.DownloadString(AppUrl);
|
|
|
|
|
|
|
|
Logger.Info("Server said hai...");
|
|
|
|
Logger.Info("Server said hai...");
|
|
|
|
_pingFailCounter = 0;
|
|
|
|
_pingFailCounter = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -92,13 +112,9 @@ namespace NzbDrone
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_pingFailCounter++;
|
|
|
|
_pingFailCounter++;
|
|
|
|
Logger.ErrorException("App is not responding. Count " + _pingFailCounter, ex);
|
|
|
|
Logger.ErrorException("App is not responding. Count " + _pingFailCounter, ex);
|
|
|
|
if (_pingFailCounter > 3)
|
|
|
|
if (_pingFailCounter > 2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_pingTimer.Stop();
|
|
|
|
RestartServer();
|
|
|
|
Logger.Warn("Attempting to restart server.");
|
|
|
|
|
|
|
|
StopIIS();
|
|
|
|
|
|
|
|
KillOrphaned();
|
|
|
|
|
|
|
|
StartIIS();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -112,42 +128,6 @@ namespace NzbDrone
|
|
|
|
IISLogger.Trace(e.Data);
|
|
|
|
IISLogger.Trace(e.Data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal static void StopIIS()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
KillProcess(IISProcess);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal static void KillOrphaned()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Info("Finding orphaned IIS Processes.");
|
|
|
|
|
|
|
|
foreach (var process in Process.GetProcessesByName("IISExpress"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string processPath = process.MainModule.FileName;
|
|
|
|
|
|
|
|
Logger.Info("[{0}]IIS Process found. Path:{1}", process.Id, processPath);
|
|
|
|
|
|
|
|
if (CleanPath(processPath) == CleanPath(IISExe))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Info("[{0}]Process is considered orphaned.", process.Id);
|
|
|
|
|
|
|
|
KillProcess(process);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Info("[{0}]Process has a different start-up path. skipping.", process.Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 void UpdateIISConfig()
|
|
|
|
private static void UpdateIISConfig()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string configPath = Path.Combine(IISFolder, @"AppServer\applicationhost.config");
|
|
|
|
string configPath = Path.Combine(IISFolder, @"AppServer\applicationhost.config");
|
|
|
@ -170,6 +150,18 @@ namespace NzbDrone
|
|
|
|
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("//", "//");
|
|
|
|