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.
pull/7/merge
kay.one 14 years ago
parent ad89618f58
commit 8686eb5d32

@ -54,11 +54,11 @@ namespace NzbDrone.Core
{ {
BindKernel(); BindKernel();
LogConfiguration.Setup(); LogConfiguration.StartDbLogging();
Migrations.Run(Connection.MainConnectionString, true); Migrations.Run(Connection.MainConnectionString, true);
SetupDefaultQualityProfiles(_kernel.Get<IRepository>()); //Setup the default QualityProfiles on start-up _kernel.Get<QualityProvider>().SetupDefaultProfiles();
BindIndexers(); BindIndexers();
BindJobs(); BindJobs();
@ -141,11 +141,11 @@ namespace NzbDrone.Core
{ {
try try
{ {
Logger.Debug("Attaching to parent process for automatic termination."); var pid = Convert.ToInt32(Environment.GetEnvironmentVariable("NZBDRONE_PID"));
var pc = new PerformanceCounter("Process", "Creating Process ID",
Process.GetCurrentProcess().ProcessName); Logger.Debug("Attaching to parent process ({0}) for automatic termination.", pid);
var pid = (int)pc.NextValue();
var hostProcess = Process.GetProcessById(pid); var hostProcess = Process.GetProcessById(Convert.ToInt32(pid));
hostProcess.EnableRaisingEvents = true; hostProcess.EnableRaisingEvents = true;
hostProcess.Exited += (delegate hostProcess.Exited += (delegate
@ -154,7 +154,7 @@ namespace NzbDrone.Core
ShutDown(); ShutDown();
}); });
Logger.Debug("Successfully Attached to host. Process ID: {0}", pid); Logger.Debug("Successfully Attached to host. Process [{0}]", hostProcess.ProcessName);
} }
catch (Exception e) catch (Exception e)
{ {
@ -167,55 +167,5 @@ namespace NzbDrone.Core
Logger.Info("Shutting down application."); Logger.Info("Shutting down application.");
Process.GetCurrentProcess().Kill(); Process.GetCurrentProcess().Kill();
} }
private static void SetupDefaultQualityProfiles(IRepository repository)
{
var sd = new QualityProfile
{
Name = "SD",
Allowed = new List<QualityTypes> { QualityTypes.SDTV, QualityTypes.DVD },
Cutoff = QualityTypes.SDTV
};
var hd = new QualityProfile
{
Name = "HD",
Allowed =
new List<QualityTypes> { 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<QualityProfile>(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<QualityProfile>(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);
}
}
} }
} }

@ -1,6 +1,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using Ninject; using Ninject;
using Ninject.Activation;
using NLog; using NLog;
using NLog.Config; using NLog.Config;
@ -17,12 +18,13 @@ namespace NzbDrone.Core.Instrumentation
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"),
false); false);
LogManager.ConfigurationReloaded += ((s, e) => BindCustomLoggers());
BindCustomLoggers(); LogManager.ConfigurationReloaded += ((s, e) => StartDbLogging());
} }
private static void BindCustomLoggers() public static void StartDbLogging()
{ {
#if Release #if Release
var exTarget = new ExceptioneerTarget(); var exTarget = new ExceptioneerTarget();
LogManager.Configuration.AddTarget("Exceptioneer", exTarget); LogManager.Configuration.AddTarget("Exceptioneer", exTarget);
@ -30,7 +32,7 @@ namespace NzbDrone.Core.Instrumentation
#endif #endif
var sonicTarget = CentralDispatch.NinjectKernel.Get<SubsonicTarget>(); var sonicTarget = CentralDispatch.NinjectKernel.Get<SubsonicTarget>();
LogManager.Configuration.AddTarget("DbLogger", sonicTarget); 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(); LogManager.Configuration.Reload();
} }

@ -53,5 +53,39 @@ namespace NzbDrone.Core.Providers
{ {
return _repository.Single<QualityProfile>(q => q.QualityProfileId == profileId); return _repository.Single<QualityProfile>(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> { QualityTypes.SDTV, QualityTypes.DVD }, Cutoff = QualityTypes.SDTV };
var hd = new QualityProfile
{
Name = "HD",
Allowed = new List<QualityTypes> { 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);
}
}
} }
} }

@ -36,9 +36,6 @@ namespace NzbDrone.Web
{ {
base.OnApplicationStarted(); base.OnApplicationStarted();
Logger.Info("NZBDrone Starting up.");
CentralDispatch.DedicateToHost();
RegisterRoutes(RouteTable.Routes); RegisterRoutes(RouteTable.Routes);
//base.OnApplicationStarted(); //base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas(); AreaRegistration.RegisterAllAreas();
@ -48,6 +45,10 @@ namespace NzbDrone.Web
protected override IKernel CreateKernel() protected override IKernel CreateKernel()
{ {
LogConfiguration.Setup();
Logger.Info("NZBDrone Starting up.");
CentralDispatch.DedicateToHost();
var kernel = CentralDispatch.NinjectKernel; var kernel = CentralDispatch.NinjectKernel;
// kernel.Bind<IRepository>().ToConstant(kernel.Get<IRepository>("LogDb")); // kernel.Bind<IRepository>().ToConstant(kernel.Get<IRepository>("LogDb"));

@ -20,6 +20,8 @@
<rules> <rules>
<logger name="IIS*" minlevel="Trace" writeTo="consoleTarget"/> <logger name="IIS*" minlevel="Trace" writeTo="consoleTarget"/>
<logger name="NzbDrone.Web.MvcApplication" minlevel="Trace" writeTo="consoleTarget"/>
<logger name="NzbDrone.Core.CentralDispatch" minlevel="Trace" writeTo="consoleTarget"/>
<logger name="Application" minlevel="Trace" writeTo="consoleTarget"/> <logger name="Application" minlevel="Trace" writeTo="consoleTarget"/>
<logger name="*" minlevel="Trace" writeTo="udpTarget"/> <logger name="*" minlevel="Trace" writeTo="udpTarget"/>
<logger name="*" minlevel="Off" writeTo="xmlFile"> <logger name="*" minlevel="Off" writeTo="xmlFile">

@ -49,7 +49,8 @@ namespace NzbDrone
IISProcess.ErrorDataReceived += (OnErrorDataReceived); IISProcess.ErrorDataReceived += (OnErrorDataReceived);
//Set Variables for the config file. //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 try
{ {
@ -148,6 +149,12 @@ namespace NzbDrone
e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called")) e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called"))
return; return;
if (e.Data.Contains(" NzbDrone."))
{
Console.WriteLine(e.Data);
return;
}
IISLogger.Trace(e.Data); IISLogger.Trace(e.Data);
} }

Loading…
Cancel
Save