mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Start configuration
This commit is contained in:
@@ -1,13 +1,19 @@
|
|||||||
using CommandLine;
|
using Autofac;
|
||||||
|
using CommandLine;
|
||||||
using CommandLine.Text;
|
using CommandLine.Text;
|
||||||
using Jackett.Common.Models.Config;
|
using Jackett.Common.Models.Config;
|
||||||
|
using Jackett.Common.Plumbing;
|
||||||
|
using Jackett.Common.Services.Interfaces;
|
||||||
using Jackett.Common.Utils;
|
using Jackett.Common.Utils;
|
||||||
|
using Jackett.Server.Services;
|
||||||
using Microsoft.AspNetCore;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using NLog;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Jackett.Server
|
namespace Jackett.Server
|
||||||
{
|
{
|
||||||
@@ -23,16 +29,17 @@ namespace Jackett.Server
|
|||||||
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 + " options:";
|
||||||
Console.WriteLine(text);
|
Environment.Exit(1);
|
||||||
Environment.ExitCode = 1;
|
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
var runtimeDictionary = new Dictionary<string, string>();
|
var runtimeDictionary = new Dictionary<string, string>();
|
||||||
|
RuntimeSettings r = new RuntimeSettings();
|
||||||
|
ConsoleOptions consoleOptions = new ConsoleOptions();
|
||||||
optionsResult.WithParsed(options =>
|
optionsResult.WithParsed(options =>
|
||||||
{
|
{
|
||||||
RuntimeSettings r = options.ToRunTimeSettings();
|
r = options.ToRunTimeSettings();
|
||||||
|
consoleOptions = options;
|
||||||
runtimeDictionary = GetValues(r);
|
runtimeDictionary = GetValues(r);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -41,7 +48,52 @@ namespace Jackett.Server
|
|||||||
|
|
||||||
Configuration = builder.Build();
|
Configuration = builder.Build();
|
||||||
|
|
||||||
CreateWebHostBuilder(args).Build().Run();
|
//hack TODO: Get the configuration without any DI
|
||||||
|
var containerBuilder = new ContainerBuilder();
|
||||||
|
Initialisation.SetupLogging(r, containerBuilder);
|
||||||
|
containerBuilder.RegisterModule(new JackettModule(r));
|
||||||
|
containerBuilder.RegisterType<ServerService>().As<IServerService>();
|
||||||
|
containerBuilder.RegisterType<SecuityService>().As<ISecuityService>();
|
||||||
|
containerBuilder.RegisterType<ProtectionService>().As<IProtectionService>();
|
||||||
|
var tempContainer = containerBuilder.Build();
|
||||||
|
|
||||||
|
Logger logger = tempContainer.Resolve<Logger>();
|
||||||
|
ServerConfig serverConfig = tempContainer.Resolve<ServerConfig>();
|
||||||
|
IConfigurationService configurationService = tempContainer.Resolve<IConfigurationService>();
|
||||||
|
IServerService serverService = tempContainer.Resolve<IServerService>();
|
||||||
|
Int32.TryParse(serverConfig.Port.ToString(), out Int32 configPort);
|
||||||
|
|
||||||
|
|
||||||
|
// Override port
|
||||||
|
if (consoleOptions.Port != 0)
|
||||||
|
{
|
||||||
|
if (configPort != consoleOptions.Port)
|
||||||
|
{
|
||||||
|
logger.Info("Overriding port to " + consoleOptions.Port);
|
||||||
|
serverConfig.Port = consoleOptions.Port;
|
||||||
|
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||||
|
if (isWindows)
|
||||||
|
{
|
||||||
|
if (ServerUtil.IsUserAdministrator())
|
||||||
|
{
|
||||||
|
serverService.ReserveUrls(doInstall: true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.Error("Unable to switch ports when not running as administrator");
|
||||||
|
Environment.Exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
configurationService.SaveConfig(serverConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] url = serverConfig.GetListenAddresses(serverConfig.AllowExternal).Take(1).ToArray(); //Kestrel doesn't need 127.0.0.1 and localhost to be registered, remove once off OWIN
|
||||||
|
|
||||||
|
tempContainer.Dispose();
|
||||||
|
tempContainer = null;
|
||||||
|
|
||||||
|
CreateWebHostBuilder(args, url).Build().Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<string, string> GetValues(object obj)
|
public static Dictionary<string, string> GetValues(object obj)
|
||||||
@@ -52,9 +104,11 @@ 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args, string[] urls) =>
|
||||||
WebHost.CreateDefaultBuilder(args)
|
WebHost.CreateDefaultBuilder(args)
|
||||||
.UseConfiguration(Configuration)
|
.UseConfiguration(Configuration)
|
||||||
|
.UseUrls(urls)
|
||||||
|
.PreferHostingUrls(true)
|
||||||
.UseStartup<Startup>();
|
.UseStartup<Startup>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user