mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Continue moving configuration across
This commit is contained in:
@@ -95,7 +95,7 @@ namespace Jackett.Server.Controllers
|
|||||||
serverConfig.RuntimeSettings.BasePath = serverService.BasePath();
|
serverConfig.RuntimeSettings.BasePath = serverService.BasePath();
|
||||||
configService.SaveConfig(serverConfig);
|
configService.SaveConfig(serverConfig);
|
||||||
|
|
||||||
Initialisation.SetLogLevel(logging ? LogLevel.Debug : LogLevel.Info);
|
Helper.SetLogLevel(logging ? LogLevel.Debug : LogLevel.Info);
|
||||||
serverConfig.RuntimeSettings.TracingEnabled = logging;
|
serverConfig.RuntimeSettings.TracingEnabled = logging;
|
||||||
|
|
||||||
if (omdbApiKey != serverConfig.OmdbApiKey)
|
if (omdbApiKey != serverConfig.OmdbApiKey)
|
||||||
|
@@ -9,13 +9,14 @@ using Jackett.Common.Utils.Clients;
|
|||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Jackett.Server
|
namespace Jackett.Server
|
||||||
{
|
{
|
||||||
public class Initialisation
|
public static class Helper
|
||||||
{
|
{
|
||||||
public static IContainer ApplicationContainer { get; set; }
|
public static IContainer ApplicationContainer { get; set; }
|
||||||
|
|
||||||
@@ -31,10 +32,87 @@ namespace Jackett.Server
|
|||||||
_automapperInitialised = true;
|
_automapperInitialised = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProcessRuntimeSettings();
|
||||||
|
|
||||||
//Load the indexers
|
//Load the indexers
|
||||||
ServerService.Initalize();
|
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()
|
private static void InitAutomapper()
|
||||||
{
|
{
|
||||||
Mapper.Initialize(cfg =>
|
Mapper.Initialize(cfg =>
|
||||||
@@ -62,8 +140,7 @@ namespace Jackett.Server
|
|||||||
{
|
{
|
||||||
if (r.Category != null)
|
if (r.Category != null)
|
||||||
{
|
{
|
||||||
var CategoryDesc = string.Join(", ", r.Category.Select(x => TorznabCatType.GetCatDesc(x)).Where(x => !string.IsNullOrEmpty(x)));
|
t.CategoryDesc = string.Join(", ", r.Category.Select(x => TorznabCatType.GetCatDesc(x)).Where(x => !string.IsNullOrEmpty(x)));
|
||||||
t.CategoryDesc = CategoryDesc;
|
|
||||||
}
|
}
|
||||||
else
|
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)
|
public static void SetupLogging(RuntimeSettings settings, ContainerBuilder builder)
|
||||||
{
|
{
|
||||||
var logFileName = settings.CustomLogFileName ?? "log.txt";
|
var logFileName = settings.CustomLogFileName ?? "log.txt";
|
@@ -15,7 +15,7 @@ namespace Jackett.Server.Middleware
|
|||||||
|| request.Path.ToString().Equals("/index.html", StringComparison.OrdinalIgnoreCase))
|
|| request.Path.ToString().Equals("/index.html", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
// 301 is the status code of permanent redirect
|
// 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;
|
var response = context.HttpContext.Response;
|
||||||
response.StatusCode = StatusCodes.Status301MovedPermanently;
|
response.StatusCode = StatusCodes.Status301MovedPermanently;
|
||||||
context.Result = RuleResult.EndResponse;
|
context.Result = RuleResult.EndResponse;
|
||||||
|
@@ -10,7 +10,7 @@ namespace Jackett.Server.Middleware
|
|||||||
{
|
{
|
||||||
var request = context.HttpContext.Request;
|
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))
|
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
|
namespace Jackett.Server
|
||||||
{
|
{
|
||||||
public class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
public static IConfiguration Configuration { get; set; }
|
public static IConfiguration Configuration { get; set; }
|
||||||
|
|
||||||
|
private static RuntimeSettings Settings { get; set; }
|
||||||
|
|
||||||
public static void Main(string[] args)
|
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 =>
|
optionsResult.WithNotParsed(errors =>
|
||||||
{
|
{
|
||||||
var text = HelpText.AutoBuild(optionsResult);
|
var text = HelpText.AutoBuild(optionsResult);
|
||||||
text.Copyright = " ";
|
text.Copyright = " ";
|
||||||
text.Heading = "Jackett v" + EnvironmentUtil.JackettVersion + " options:";
|
text.Heading = "Jackett v" + EnvironmentUtil.JackettVersion;
|
||||||
|
Console.WriteLine(text);
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
var runtimeDictionary = new Dictionary<string, string>();
|
var runtimeDictionary = new Dictionary<string, string>();
|
||||||
RuntimeSettings runtimeSettings = new RuntimeSettings();
|
|
||||||
ConsoleOptions consoleOptions = new ConsoleOptions();
|
ConsoleOptions consoleOptions = new ConsoleOptions();
|
||||||
optionsResult.WithParsed(options =>
|
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;
|
consoleOptions = options;
|
||||||
runtimeDictionary = GetValues(runtimeSettings);
|
runtimeDictionary = GetValues(Settings);
|
||||||
});
|
});
|
||||||
|
|
||||||
var builder = new ConfigurationBuilder();
|
var builder = new ConfigurationBuilder();
|
||||||
@@ -51,8 +63,8 @@ namespace Jackett.Server
|
|||||||
|
|
||||||
//hack TODO: Get the configuration without any DI
|
//hack TODO: Get the configuration without any DI
|
||||||
var containerBuilder = new ContainerBuilder();
|
var containerBuilder = new ContainerBuilder();
|
||||||
Initialisation.SetupLogging(runtimeSettings, containerBuilder);
|
Helper.SetupLogging(Settings, containerBuilder);
|
||||||
containerBuilder.RegisterModule(new JackettModule(runtimeSettings));
|
containerBuilder.RegisterModule(new JackettModule(Settings));
|
||||||
containerBuilder.RegisterType<ServerService>().As<IServerService>();
|
containerBuilder.RegisterType<ServerService>().As<IServerService>();
|
||||||
containerBuilder.RegisterType<SecuityService>().As<ISecuityService>();
|
containerBuilder.RegisterType<SecuityService>().As<ISecuityService>();
|
||||||
containerBuilder.RegisterType<ProtectionService>().As<IProtectionService>();
|
containerBuilder.RegisterType<ProtectionService>().As<IProtectionService>();
|
||||||
@@ -64,7 +76,7 @@ namespace Jackett.Server
|
|||||||
IServerService serverService = tempContainer.Resolve<IServerService>();
|
IServerService serverService = tempContainer.Resolve<IServerService>();
|
||||||
Int32.TryParse(serverConfig.Port.ToString(), out Int32 configPort);
|
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)
|
if (!dataProtectionFolder.Exists)
|
||||||
{
|
{
|
||||||
dataProtectionFolder.Create();
|
dataProtectionFolder.Create();
|
||||||
@@ -110,6 +122,26 @@ namespace Jackett.Server
|
|||||||
.ToDictionary(p => "RuntimeSettings:" + p.Name, p => p.GetValue(obj) == null ? null : p.GetValue(obj).ToString());
|
.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) =>
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args, string[] urls) =>
|
||||||
WebHost.CreateDefaultBuilder(args)
|
WebHost.CreateDefaultBuilder(args)
|
||||||
.UseConfiguration(Configuration)
|
.UseConfiguration(Configuration)
|
||||||
|
@@ -74,7 +74,7 @@ namespace Jackett.Server
|
|||||||
|
|
||||||
var builder = new ContainerBuilder();
|
var builder = new ContainerBuilder();
|
||||||
|
|
||||||
Initialisation.SetupLogging(runtimeSettings, builder);
|
Helper.SetupLogging(runtimeSettings, builder);
|
||||||
|
|
||||||
builder.Populate(services);
|
builder.Populate(services);
|
||||||
builder.RegisterModule(new JackettModule(runtimeSettings));
|
builder.RegisterModule(new JackettModule(runtimeSettings));
|
||||||
@@ -83,15 +83,17 @@ namespace Jackett.Server
|
|||||||
builder.RegisterType<ProtectionService>().As<IProtectionService>();
|
builder.RegisterType<ProtectionService>().As<IProtectionService>();
|
||||||
|
|
||||||
IContainer container = builder.Build();
|
IContainer container = builder.Build();
|
||||||
Initialisation.ApplicationContainer = container;
|
Helper.ApplicationContainer = container;
|
||||||
|
|
||||||
|
Helper.Initialize();
|
||||||
|
|
||||||
return new AutofacServiceProvider(container);
|
return new AutofacServiceProvider(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// 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();
|
app.UseResponseCompression();
|
||||||
|
|
||||||
@@ -107,7 +109,7 @@ namespace Jackett.Server
|
|||||||
|
|
||||||
app.UseFileServer(new FileServerOptions
|
app.UseFileServer(new FileServerOptions
|
||||||
{
|
{
|
||||||
FileProvider = new PhysicalFileProvider(Initialisation.ConfigService.GetContentFolder()),
|
FileProvider = new PhysicalFileProvider(Helper.ConfigService.GetContentFolder()),
|
||||||
RequestPath = "",
|
RequestPath = "",
|
||||||
EnableDefaultFiles = true,
|
EnableDefaultFiles = true,
|
||||||
EnableDirectoryBrowsing = false
|
EnableDirectoryBrowsing = false
|
||||||
@@ -117,5 +119,10 @@ namespace Jackett.Server
|
|||||||
|
|
||||||
app.UseMvc();
|
app.UseMvc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnShutdown()
|
||||||
|
{
|
||||||
|
//this code is called when the application stops
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user