mirror of https://github.com/Jackett/Jackett
Continue moving configuration across
This commit is contained in:
parent
e4c729a588
commit
23f55ef33a
|
@ -95,7 +95,7 @@ namespace Jackett.Server.Controllers
|
|||
serverConfig.RuntimeSettings.BasePath = serverService.BasePath();
|
||||
configService.SaveConfig(serverConfig);
|
||||
|
||||
Initialisation.SetLogLevel(logging ? LogLevel.Debug : LogLevel.Info);
|
||||
Helper.SetLogLevel(logging ? LogLevel.Debug : LogLevel.Info);
|
||||
serverConfig.RuntimeSettings.TracingEnabled = logging;
|
||||
|
||||
if (omdbApiKey != serverConfig.OmdbApiKey)
|
||||
|
|
|
@ -9,13 +9,14 @@ using Jackett.Common.Utils.Clients;
|
|||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Jackett.Server
|
||||
{
|
||||
public class Initialisation
|
||||
public static class Helper
|
||||
{
|
||||
public static IContainer ApplicationContainer { get; set; }
|
||||
|
||||
|
@ -31,10 +32,87 @@ namespace Jackett.Server
|
|||
_automapperInitialised = true;
|
||||
}
|
||||
|
||||
ProcessRuntimeSettings();
|
||||
|
||||
//Load the indexers
|
||||
ServerService.Initalize();
|
||||
}
|
||||
|
||||
private static void ProcessRuntimeSettings()
|
||||
{
|
||||
RuntimeSettings runtimeSettings = ServerConfiguration.RuntimeSettings;
|
||||
|
||||
if (runtimeSettings.ClientOverride != "httpclient" && runtimeSettings.ClientOverride != "httpclient2")
|
||||
{
|
||||
Logger.Error($"Client override ({runtimeSettings.ClientOverride}) has been deprecated, please remove it from your start arguments");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
if (runtimeSettings.DoSSLFix != null)
|
||||
{
|
||||
Logger.Error("SSLFix has been deprecated, please remove it from your start arguments");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
if (runtimeSettings.LogRequests)
|
||||
{
|
||||
Logger.Info("Logging enabled.");
|
||||
}
|
||||
|
||||
if (runtimeSettings.TracingEnabled)
|
||||
{
|
||||
Logger.Info("Tracing enabled.");
|
||||
}
|
||||
|
||||
if (runtimeSettings.IgnoreSslErrors == true)
|
||||
{
|
||||
Logger.Info("Jackett will ignore SSL certificate errors.");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(runtimeSettings.CustomDataFolder))
|
||||
{
|
||||
Logger.Info("Jackett Data will be stored in: " + runtimeSettings.CustomDataFolder);
|
||||
}
|
||||
|
||||
// Use Proxy
|
||||
if (runtimeSettings.ProxyConnection != null)
|
||||
{
|
||||
Logger.Info("Proxy enabled. " + runtimeSettings.ProxyConnection);
|
||||
}
|
||||
}
|
||||
|
||||
public static IConfigurationService ConfigService
|
||||
{
|
||||
get
|
||||
{
|
||||
return ApplicationContainer.Resolve<IConfigurationService>();
|
||||
}
|
||||
}
|
||||
|
||||
public static IServerService ServerService
|
||||
{
|
||||
get
|
||||
{
|
||||
return ApplicationContainer.Resolve<IServerService>();
|
||||
}
|
||||
}
|
||||
|
||||
public static ServerConfig ServerConfiguration
|
||||
{
|
||||
get
|
||||
{
|
||||
return ApplicationContainer.Resolve<ServerConfig>();
|
||||
}
|
||||
}
|
||||
|
||||
public static Logger Logger
|
||||
{
|
||||
get
|
||||
{
|
||||
return ApplicationContainer.Resolve<Logger>();
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitAutomapper()
|
||||
{
|
||||
Mapper.Initialize(cfg =>
|
||||
|
@ -62,8 +140,7 @@ namespace Jackett.Server
|
|||
{
|
||||
if (r.Category != null)
|
||||
{
|
||||
var CategoryDesc = string.Join(", ", r.Category.Select(x => TorznabCatType.GetCatDesc(x)).Where(x => !string.IsNullOrEmpty(x)));
|
||||
t.CategoryDesc = CategoryDesc;
|
||||
t.CategoryDesc = string.Join(", ", r.Category.Select(x => TorznabCatType.GetCatDesc(x)).Where(x => !string.IsNullOrEmpty(x)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -73,22 +150,6 @@ namespace Jackett.Server
|
|||
});
|
||||
}
|
||||
|
||||
public static IConfigurationService ConfigService
|
||||
{
|
||||
get
|
||||
{
|
||||
return ApplicationContainer.Resolve<IConfigurationService>();
|
||||
}
|
||||
}
|
||||
|
||||
public static IServerService ServerService
|
||||
{
|
||||
get
|
||||
{
|
||||
return ApplicationContainer.Resolve<IServerService>();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetupLogging(RuntimeSettings settings, ContainerBuilder builder)
|
||||
{
|
||||
var logFileName = settings.CustomLogFileName ?? "log.txt";
|
|
@ -15,7 +15,7 @@ namespace Jackett.Server.Middleware
|
|||
|| request.Path.ToString().Equals("/index.html", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// 301 is the status code of permanent redirect
|
||||
var redir = Initialisation.ServerService.BasePath() + "/UI/Dashboard";
|
||||
var redir = Helper.ServerService.BasePath() + "/UI/Dashboard";
|
||||
var response = context.HttpContext.Response;
|
||||
response.StatusCode = StatusCodes.Status301MovedPermanently;
|
||||
context.Result = RuleResult.EndResponse;
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Jackett.Server.Middleware
|
|||
{
|
||||
var request = context.HttpContext.Request;
|
||||
|
||||
string serverBasePath = Initialisation.ServerService.BasePath() ?? string.Empty;
|
||||
string serverBasePath = Helper.ServerService.BasePath() ?? string.Empty;
|
||||
|
||||
if (request.Path != null && request.Path.HasValue && serverBasePath.Length > 0 && request.Path.Value.StartsWith(serverBasePath, StringComparison.Ordinal))
|
||||
{
|
||||
|
|
|
@ -18,30 +18,42 @@ using System.Runtime.InteropServices;
|
|||
|
||||
namespace Jackett.Server
|
||||
{
|
||||
public class Program
|
||||
public static class Program
|
||||
{
|
||||
public static IConfiguration Configuration { get; set; }
|
||||
|
||||
private static RuntimeSettings Settings { get; set; }
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var optionsResult = Parser.Default.ParseArguments<ConsoleOptions>(args);
|
||||
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
|
||||
|
||||
var parser = new Parser();
|
||||
var optionsResult = parser.ParseArguments<ConsoleOptions>(args);
|
||||
|
||||
optionsResult.WithNotParsed(errors =>
|
||||
{
|
||||
var text = HelpText.AutoBuild(optionsResult);
|
||||
text.Copyright = " ";
|
||||
text.Heading = "Jackett v" + EnvironmentUtil.JackettVersion + " options:";
|
||||
text.Heading = "Jackett v" + EnvironmentUtil.JackettVersion;
|
||||
Console.WriteLine(text);
|
||||
Environment.Exit(1);
|
||||
return;
|
||||
});
|
||||
|
||||
var runtimeDictionary = new Dictionary<string, string>();
|
||||
RuntimeSettings runtimeSettings = new RuntimeSettings();
|
||||
ConsoleOptions consoleOptions = new ConsoleOptions();
|
||||
optionsResult.WithParsed(options =>
|
||||
{
|
||||
runtimeSettings = options.ToRunTimeSettings();
|
||||
if (string.IsNullOrEmpty(options.Client))
|
||||
{
|
||||
//TODO: Remove libcurl once off owin
|
||||
options.Client = "httpclient";
|
||||
}
|
||||
|
||||
Settings = options.ToRunTimeSettings();
|
||||
consoleOptions = options;
|
||||
runtimeDictionary = GetValues(runtimeSettings);
|
||||
runtimeDictionary = GetValues(Settings);
|
||||
});
|
||||
|
||||
var builder = new ConfigurationBuilder();
|
||||
|
@ -51,8 +63,8 @@ namespace Jackett.Server
|
|||
|
||||
//hack TODO: Get the configuration without any DI
|
||||
var containerBuilder = new ContainerBuilder();
|
||||
Initialisation.SetupLogging(runtimeSettings, containerBuilder);
|
||||
containerBuilder.RegisterModule(new JackettModule(runtimeSettings));
|
||||
Helper.SetupLogging(Settings, containerBuilder);
|
||||
containerBuilder.RegisterModule(new JackettModule(Settings));
|
||||
containerBuilder.RegisterType<ServerService>().As<IServerService>();
|
||||
containerBuilder.RegisterType<SecuityService>().As<ISecuityService>();
|
||||
containerBuilder.RegisterType<ProtectionService>().As<IProtectionService>();
|
||||
|
@ -64,7 +76,7 @@ namespace Jackett.Server
|
|||
IServerService serverService = tempContainer.Resolve<IServerService>();
|
||||
Int32.TryParse(serverConfig.Port.ToString(), out Int32 configPort);
|
||||
|
||||
DirectoryInfo dataProtectionFolder = new DirectoryInfo(Path.Combine(runtimeSettings.DataFolder, "DataProtection"));
|
||||
DirectoryInfo dataProtectionFolder = new DirectoryInfo(Path.Combine(Settings.DataFolder, "DataProtection"));
|
||||
if (!dataProtectionFolder.Exists)
|
||||
{
|
||||
dataProtectionFolder.Create();
|
||||
|
@ -110,6 +122,26 @@ namespace Jackett.Server
|
|||
.ToDictionary(p => "RuntimeSettings:" + p.Name, p => p.GetValue(obj) == null ? null : p.GetValue(obj).ToString());
|
||||
}
|
||||
|
||||
private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Settings != null && !string.IsNullOrWhiteSpace(Settings.PIDFile))
|
||||
{
|
||||
var PIDFile = Settings.PIDFile;
|
||||
if (File.Exists(PIDFile))
|
||||
{
|
||||
Console.WriteLine("Deleting PID file " + PIDFile);
|
||||
File.Delete(PIDFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine(ex.ToString(), "Error while deleting the PID file");
|
||||
}
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args, string[] urls) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseConfiguration(Configuration)
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace Jackett.Server
|
|||
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
Initialisation.SetupLogging(runtimeSettings, builder);
|
||||
Helper.SetupLogging(runtimeSettings, builder);
|
||||
|
||||
builder.Populate(services);
|
||||
builder.RegisterModule(new JackettModule(runtimeSettings));
|
||||
|
@ -83,15 +83,17 @@ namespace Jackett.Server
|
|||
builder.RegisterType<ProtectionService>().As<IProtectionService>();
|
||||
|
||||
IContainer container = builder.Build();
|
||||
Initialisation.ApplicationContainer = container;
|
||||
Helper.ApplicationContainer = container;
|
||||
|
||||
Helper.Initialize();
|
||||
|
||||
return new AutofacServiceProvider(container);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime)
|
||||
{
|
||||
Initialisation.Initialize();
|
||||
applicationLifetime.ApplicationStopping.Register(OnShutdown);
|
||||
|
||||
app.UseResponseCompression();
|
||||
|
||||
|
@ -107,7 +109,7 @@ namespace Jackett.Server
|
|||
|
||||
app.UseFileServer(new FileServerOptions
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(Initialisation.ConfigService.GetContentFolder()),
|
||||
FileProvider = new PhysicalFileProvider(Helper.ConfigService.GetContentFolder()),
|
||||
RequestPath = "",
|
||||
EnableDefaultFiles = true,
|
||||
EnableDirectoryBrowsing = false
|
||||
|
@ -117,5 +119,10 @@ namespace Jackett.Server
|
|||
|
||||
app.UseMvc();
|
||||
}
|
||||
|
||||
private void OnShutdown()
|
||||
{
|
||||
//this code is called when the application stops
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue