From 8686eb5d322ac9ae2d9f8965eb37df8e77177665 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 12 Jun 2011 20:45:22 -0700 Subject: [PATCH] IISExpress is now attached to NZBDrone.exe earlier, which means it should almost have a garanteed termination as soon as the host is killed. Console logging starts earlier in the app. Moved Default profiles to QualityProvider. --- NzbDrone.Core/CentralDispatch.cs | 66 +++---------------- .../Instrumentation/LogConfiguration.cs | 10 +-- NzbDrone.Core/Providers/QualityProvider.cs | 34 ++++++++++ NzbDrone.Web/Global.asax.cs | 7 +- NzbDrone.Web/log.config | 2 + NzbDrone/IISController.cs | 11 +++- 6 files changed, 63 insertions(+), 67 deletions(-) diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 50b96583c..c4a3c3dd5 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -54,11 +54,11 @@ namespace NzbDrone.Core { BindKernel(); - LogConfiguration.Setup(); + LogConfiguration.StartDbLogging(); Migrations.Run(Connection.MainConnectionString, true); - SetupDefaultQualityProfiles(_kernel.Get()); //Setup the default QualityProfiles on start-up + _kernel.Get().SetupDefaultProfiles(); BindIndexers(); BindJobs(); @@ -141,11 +141,11 @@ namespace NzbDrone.Core { try { - Logger.Debug("Attaching to parent process for automatic termination."); - var pc = new PerformanceCounter("Process", "Creating Process ID", - Process.GetCurrentProcess().ProcessName); - var pid = (int)pc.NextValue(); - var hostProcess = Process.GetProcessById(pid); + var pid = Convert.ToInt32(Environment.GetEnvironmentVariable("NZBDRONE_PID")); + + Logger.Debug("Attaching to parent process ({0}) for automatic termination.", pid); + + var hostProcess = Process.GetProcessById(Convert.ToInt32(pid)); hostProcess.EnableRaisingEvents = true; hostProcess.Exited += (delegate @@ -154,7 +154,7 @@ namespace NzbDrone.Core ShutDown(); }); - Logger.Debug("Successfully Attached to host. Process ID: {0}", pid); + Logger.Debug("Successfully Attached to host. Process [{0}]", hostProcess.ProcessName); } catch (Exception e) { @@ -167,55 +167,5 @@ namespace NzbDrone.Core Logger.Info("Shutting down application."); Process.GetCurrentProcess().Kill(); } - - private static void SetupDefaultQualityProfiles(IRepository repository) - { - var sd = new QualityProfile - { - Name = "SD", - Allowed = new List { QualityTypes.SDTV, QualityTypes.DVD }, - Cutoff = QualityTypes.SDTV - }; - - var hd = new QualityProfile - { - Name = "HD", - Allowed = - new List { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720p }, - Cutoff = QualityTypes.HDTV - }; - - //Add or Update SD - Logger.Debug(String.Format("Checking for default QualityProfile: {0}", sd.Name)); - var sdDb = repository.Single(i => i.Name == sd.Name); - if (sdDb == null) - { - Logger.Debug(String.Format("Adding new default QualityProfile: {0}", sd.Name)); - repository.Add(sd); - } - - else - { - Logger.Debug(String.Format("Updating default QualityProfile: {0}", sd.Name)); - sd.QualityProfileId = sdDb.QualityProfileId; - repository.Update(sd); - } - - //Add or Update HD - Logger.Debug(String.Format("Checking for default QualityProfile: {0}", hd.Name)); - var hdDb = repository.Single(i => i.Name == hd.Name); - if (hdDb == null) - { - Logger.Debug(String.Format("Adding new default QualityProfile: {0}", hd.Name)); - repository.Add(hd); - } - - else - { - Logger.Debug(String.Format("Updating default QualityProfile: {0}", hd.Name)); - hd.QualityProfileId = hdDb.QualityProfileId; - repository.Update(hd); - } - } } } \ No newline at end of file diff --git a/NzbDrone.Core/Instrumentation/LogConfiguration.cs b/NzbDrone.Core/Instrumentation/LogConfiguration.cs index e57ddc52d..21b75225f 100644 --- a/NzbDrone.Core/Instrumentation/LogConfiguration.cs +++ b/NzbDrone.Core/Instrumentation/LogConfiguration.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.IO; using Ninject; +using Ninject.Activation; using NLog; using NLog.Config; @@ -17,12 +18,13 @@ namespace NzbDrone.Core.Instrumentation LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false); - LogManager.ConfigurationReloaded += ((s, e) => BindCustomLoggers()); - BindCustomLoggers(); + + LogManager.ConfigurationReloaded += ((s, e) => StartDbLogging()); } - private static void BindCustomLoggers() + public static void StartDbLogging() { + #if Release var exTarget = new ExceptioneerTarget(); LogManager.Configuration.AddTarget("Exceptioneer", exTarget); @@ -30,7 +32,7 @@ namespace NzbDrone.Core.Instrumentation #endif var sonicTarget = CentralDispatch.NinjectKernel.Get(); LogManager.Configuration.AddTarget("DbLogger", sonicTarget); - LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Info, sonicTarget)); + LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, sonicTarget)); LogManager.Configuration.Reload(); } diff --git a/NzbDrone.Core/Providers/QualityProvider.cs b/NzbDrone.Core/Providers/QualityProvider.cs index 939c3832c..6a5ff341c 100644 --- a/NzbDrone.Core/Providers/QualityProvider.cs +++ b/NzbDrone.Core/Providers/QualityProvider.cs @@ -53,5 +53,39 @@ namespace NzbDrone.Core.Providers { return _repository.Single(q => q.QualityProfileId == profileId); } + + public virtual void SetupDefaultProfiles() + { + Logger.Info("Setting up default quality profiles"); + + var profiles = GetAllProfiles(); + + var sd = new QualityProfile { Name = "SD", Allowed = new List { QualityTypes.SDTV, QualityTypes.DVD }, Cutoff = QualityTypes.SDTV }; + + var hd = new QualityProfile + { + Name = "HD", + Allowed = new List { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720p }, + Cutoff = QualityTypes.HDTV + }; + + //Add or Update SD + Logger.Debug(String.Format("Checking for default QualityProfile: {0}", sd.Name)); + var sdDb = profiles.Where(p => p.Name == sd.Name).FirstOrDefault(); + if (sdDb == null) + { + Logger.Debug(String.Format("Adding new default QualityProfile: {0}", sd.Name)); + Add(sd); + } + + //Add or Update HD + Logger.Debug(String.Format("Checking for default QualityProfile: {0}", hd.Name)); + var hdDb = profiles.Where(p => p.Name == hd.Name).FirstOrDefault(); + if (hdDb == null) + { + Logger.Debug(String.Format("Adding new default QualityProfile: {0}", hd.Name)); + Add(hd); + } + } } } \ No newline at end of file diff --git a/NzbDrone.Web/Global.asax.cs b/NzbDrone.Web/Global.asax.cs index d23b6085a..182f1d62a 100644 --- a/NzbDrone.Web/Global.asax.cs +++ b/NzbDrone.Web/Global.asax.cs @@ -36,9 +36,6 @@ namespace NzbDrone.Web { base.OnApplicationStarted(); - Logger.Info("NZBDrone Starting up."); - CentralDispatch.DedicateToHost(); - RegisterRoutes(RouteTable.Routes); //base.OnApplicationStarted(); AreaRegistration.RegisterAllAreas(); @@ -48,6 +45,10 @@ namespace NzbDrone.Web protected override IKernel CreateKernel() { + LogConfiguration.Setup(); + Logger.Info("NZBDrone Starting up."); + CentralDispatch.DedicateToHost(); + var kernel = CentralDispatch.NinjectKernel; // kernel.Bind().ToConstant(kernel.Get("LogDb")); diff --git a/NzbDrone.Web/log.config b/NzbDrone.Web/log.config index 8abd77ebc..74a10037b 100644 --- a/NzbDrone.Web/log.config +++ b/NzbDrone.Web/log.config @@ -20,6 +20,8 @@ + + diff --git a/NzbDrone/IISController.cs b/NzbDrone/IISController.cs index 23b7c9e91..7721d5262 100644 --- a/NzbDrone/IISController.cs +++ b/NzbDrone/IISController.cs @@ -49,7 +49,8 @@ namespace NzbDrone IISProcess.ErrorDataReceived += (OnErrorDataReceived); //Set Variables for the config file. - Environment.SetEnvironmentVariable("NZBDRONE_PATH", Config.ProjectRoot); + IISProcess.StartInfo.EnvironmentVariables.Add("NZBDRONE_PATH", Config.ProjectRoot); + IISProcess.StartInfo.EnvironmentVariables.Add("NZBDRONE_PID", Process.GetCurrentProcess().Id.ToString()); try { @@ -120,7 +121,7 @@ namespace NzbDrone try { var response = new WebClient().DownloadString(AppUrl + "/health"); - + if (!response.Contains("OK")) { throw new ServerException("Health services responded with an invalid response."); @@ -148,6 +149,12 @@ namespace NzbDrone e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called")) return; + if (e.Data.Contains(" NzbDrone.")) + { + Console.WriteLine(e.Data); + return; + } + IISLogger.Trace(e.Data); }