Added HealthController to web project for IIS Ping to use

pull/6/head
kay.one 14 years ago
parent b4ea8838d2
commit 0e191f6a44

@ -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);
}
}
}

@ -3,6 +3,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Runtime.Remoting;
using System.Timers; using System.Timers;
using System.Xml.Linq; using System.Xml.Linq;
using System.Xml.XPath; using System.Xml.XPath;
@ -71,7 +72,7 @@ namespace NzbDrone
//Start Ping //Start Ping
_pingTimer = new Timer(10000) { AutoReset = true }; _pingTimer = new Timer(10000) { AutoReset = true };
_pingTimer.Elapsed += (Server); _pingTimer.Elapsed += (PingServer);
_pingTimer.Start(); _pingTimer.Start();
return IISProcess; return IISProcess;
@ -114,11 +115,16 @@ namespace NzbDrone
StartServer(); StartServer();
} }
private static void Server(object sender, ElapsedEventArgs e) private static void PingServer(object sender, ElapsedEventArgs e)
{ {
try 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) if (_pingFailCounter > 0)
{ {
Logger.Info("Application pool has been successfully recovered."); Logger.Info("Application pool has been successfully recovered.");

Loading…
Cancel
Save