diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 50b96583c3..c4a3c3dd5e 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -54,11 +54,11 @@ private static void InitializeApp() { 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 @@ public static void DedicateToHost() { 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 @@ public static void DedicateToHost() 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 @@ private static void ShutDown() 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 e57ddc52d3..21b75225fc 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 @@ public static void Setup() 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 @@ private static void BindCustomLoggers() #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 939c3832c5..6a5ff341c6 100644 --- a/NzbDrone.Core/Providers/QualityProvider.cs +++ b/NzbDrone.Core/Providers/QualityProvider.cs @@ -53,5 +53,39 @@ public virtual QualityProfile Find(int profileId) { 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 d23b6085ac..182f1d62a5 100644 --- a/NzbDrone.Web/Global.asax.cs +++ b/NzbDrone.Web/Global.asax.cs @@ -36,9 +36,6 @@ protected override void OnApplicationStarted() { base.OnApplicationStarted(); - Logger.Info("NZBDrone Starting up."); - CentralDispatch.DedicateToHost(); - RegisterRoutes(RouteTable.Routes); //base.OnApplicationStarted(); AreaRegistration.RegisterAllAreas(); @@ -48,6 +45,10 @@ protected override void OnApplicationStarted() 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 8abd77ebc1..74a10037b9 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 23b7c9e91d..7721d5262e 100644 --- a/NzbDrone/IISController.cs +++ b/NzbDrone/IISController.cs @@ -49,7 +49,8 @@ internal static Process StartServer() 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 @@ private static void PingServer(object sender, ElapsedEventArgs e) 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 @@ private static void OnOutputDataReceived(object s, DataReceivedEventArgs e) e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called")) return; + if (e.Data.Contains(" NzbDrone.")) + { + Console.WriteLine(e.Data); + return; + } + IISLogger.Trace(e.Data); }