mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Restart WebHost after port change in UI
This commit is contained in:
@@ -8,6 +8,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Jackett.Server.Controllers
|
namespace Jackett.Server.Controllers
|
||||||
{
|
{
|
||||||
@@ -160,15 +161,9 @@ namespace Jackett.Server.Controllers
|
|||||||
serverService.ReserveUrls(true);
|
serverService.ReserveUrls(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO
|
|
||||||
//(new Thread(() =>
|
Thread.Sleep(500);
|
||||||
//{
|
Helper.RestartWebHost();
|
||||||
// Thread.Sleep(500);
|
|
||||||
// serverService.Stop();
|
|
||||||
// Engine.BuildContainer(serverConfig.RuntimeSettings, new WebApi2Module());
|
|
||||||
// Engine.Server.Initalize();
|
|
||||||
// Engine.Server.Start();
|
|
||||||
//})).Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saveDir != serverConfig.BlackholeDir)
|
if (saveDir != serverConfig.BlackholeDir)
|
||||||
|
@@ -63,6 +63,8 @@ namespace Jackett.Server
|
|||||||
|
|
||||||
Configuration = builder.Build();
|
Configuration = builder.Build();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
//hack TODO: Get the configuration without any DI
|
//hack TODO: Get the configuration without any DI
|
||||||
var containerBuilder = new ContainerBuilder();
|
var containerBuilder = new ContainerBuilder();
|
||||||
Helper.SetupLogging(Settings, containerBuilder);
|
Helper.SetupLogging(Settings, containerBuilder);
|
||||||
@@ -78,12 +80,8 @@ 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(Settings.DataFolder, "DataProtection"));
|
if (!isWebHostRestart)
|
||||||
if (!dataProtectionFolder.Exists)
|
|
||||||
{
|
{
|
||||||
dataProtectionFolder.Create();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override port
|
// Override port
|
||||||
if (consoleOptions.Port != 0)
|
if (consoleOptions.Port != 0)
|
||||||
{
|
{
|
||||||
@@ -107,18 +105,30 @@ namespace Jackett.Server
|
|||||||
configurationService.SaveConfig(serverConfig);
|
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
|
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
|
||||||
|
|
||||||
|
isWebHostRestart = false;
|
||||||
tempContainer.Dispose();
|
tempContainer.Dispose();
|
||||||
tempContainer = null;
|
tempContainer = null;
|
||||||
|
|
||||||
//TODO Handle scenario where user changes the port in the UI and we need to restart the WebHost with new port
|
try
|
||||||
do
|
|
||||||
{
|
{
|
||||||
isWebHostRestart = false;
|
|
||||||
CreateWebHostBuilder(args, url).Build().Run();
|
CreateWebHostBuilder(args, url).Build().Run();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (ex.InnerException is Microsoft.AspNetCore.Connections.AddressInUseException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Address already in use: Most likely Jackett is already running. " + ex.Message);
|
||||||
|
Environment.Exit(1);
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
} while (isWebHostRestart);
|
} while (isWebHostRestart);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<string, string> GetValues(object obj)
|
public static Dictionary<string, string> GetValues(object obj)
|
||||||
|
Reference in New Issue
Block a user