From 0e191f6a44375f7dee93ecace10b10afb5b36c36 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 18 May 2011 20:57:03 -0700 Subject: [PATCH] Added HealthController to web project for IIS Ping to use --- NzbDrone.Web/Controllers/HealthController.cs | 21 ++++++++++++++++++++ NzbDrone/IISController.cs | 12 ++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 NzbDrone.Web/Controllers/HealthController.cs diff --git a/NzbDrone.Web/Controllers/HealthController.cs b/NzbDrone.Web/Controllers/HealthController.cs new file mode 100644 index 000000000..7d29862e4 --- /dev/null +++ b/NzbDrone.Web/Controllers/HealthController.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace NzbDrone.Web.Controllers +{ + public class HealthController : Controller + { + // + // GET: /Health/ + + [HttpGet] + public JsonResult Index() + { + return Json("OK", JsonRequestBehavior.AllowGet); + } + + } +} diff --git a/NzbDrone/IISController.cs b/NzbDrone/IISController.cs index 52e1390e6..034a985cd 100644 --- a/NzbDrone/IISController.cs +++ b/NzbDrone/IISController.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Net; +using System.Runtime.Remoting; using System.Timers; using System.Xml.Linq; using System.Xml.XPath; @@ -71,7 +72,7 @@ namespace NzbDrone //Start Ping _pingTimer = new Timer(10000) { AutoReset = true }; - _pingTimer.Elapsed += (Server); + _pingTimer.Elapsed += (PingServer); _pingTimer.Start(); return IISProcess; @@ -114,11 +115,16 @@ namespace NzbDrone StartServer(); } - private static void Server(object sender, ElapsedEventArgs e) + private static void PingServer(object sender, ElapsedEventArgs e) { try { - new WebClient().DownloadString(AppUrl); + var response = new WebClient().DownloadString(AppUrl + "/health"); + + if (!response.Contains("OK")) + { + throw new ServerException("Health services responded with an invalid response."); + } if (_pingFailCounter > 0) { Logger.Info("Application pool has been successfully recovered.");