54 public async ValueTask<IServer?>
CreateServer(
string[] args,
string? updatePath, CancellationToken cancellationToken)
56 ArgumentNullException.ThrowIfNull(args);
59 if (!args.Any(arg => arg.Contains(
"hostBuilder:reloadConfigOnChange", StringComparison.OrdinalIgnoreCase))
60 && String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(
"hostBuilder__reloadConfigOnChange")))
63 args =
new string[oldArgs.Length + 1];
64 Array.Copy(oldArgs, args, oldArgs.Length);
65 args[oldArgs.Length] =
"--hostBuilder:reloadConfigOnChange=false";
68 const string AppSettingsRelocationKey = $
"--{AppSettings}-base-path=";
70 var appsettingsRelativeBasePathArgument = args.FirstOrDefault(arg => arg.StartsWith(AppSettingsRelocationKey, StringComparison.Ordinal));
72 if (appsettingsRelativeBasePathArgument !=
null)
73 basePath =
IOManager.
ResolvePath(appsettingsRelativeBasePathArgument[AppSettingsRelocationKey.Length..]);
79 Environment.SetEnvironmentVariable($
"{InternalConfiguration.Section}__{nameof(InternalConfiguration.AppSettingsBasePath)}", basePath);
81 IHostBuilder CreateDefaultBuilder() => Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
82 .ConfigureAppConfiguration((context, builder) =>
84 builder.SetBasePath(basePath);
86 builder.AddYamlFile($
"{AppSettings}.yml", optional:
true, reloadOnChange:
false)
87 .AddYamlFile($
"{AppSettings}.{context.HostingEnvironment.EnvironmentName}.yml", optional:
true, reloadOnChange:
false);
91 var environmentJsonConfig = builder.Sources[2];
92 var envConfig = builder.Sources[3];
97#error Validate this monstrosity works on current .NET
99 IConfigurationSource? cmdLineConfig;
100 IConfigurationSource baseYmlConfig, environmentYmlConfig;
101 if (args.Length == 0)
103 cmdLineConfig =
null;
104 baseYmlConfig = builder.Sources[4];
105 environmentYmlConfig = builder.Sources[5];
109 cmdLineConfig = builder.Sources[4];
110 baseYmlConfig = builder.Sources[5];
111 environmentYmlConfig = builder.Sources[6];
114 builder.Sources[2] = baseYmlConfig;
115 builder.Sources[3] = environmentJsonConfig;
116 builder.Sources[4] = environmentYmlConfig;
117 builder.Sources[5] = envConfig;
119 if (cmdLineConfig !=
null)
121 builder.Sources[6] = cmdLineConfig;
125 var setupWizardHostBuilder = CreateDefaultBuilder()
129 using (var setupHost = setupWizardHostBuilder.Build())
131 ILogger<ServerFactory> logger = setupHost.Services.GetRequiredService<ILogger<ServerFactory>>();
133 await setupHost.RunAsync(cancellationToken);
135 if (postSetupServices.GeneralConfiguration.SetupWizardMode ==
SetupWizardMode.Only)
137 logger.LogInformation(
"Shutting down due to only running setup wizard.");
141 if (postSetupServices.ReloadRequired)
143 logger.LogInformation(
"TGS must restart to reload the updated configuration.");
148 var hostBuilder = CreateDefaultBuilder()
149 .ConfigureWebHost(webHostBuilder =>
151 .UseKestrel(kestrelOptions =>
153 var serverPortProvider = kestrelOptions.ApplicationServices.GetRequiredService<
IServerPortProvider>();
154 kestrelOptions.ListenAnyIP(
155 serverPortProvider.HttpApiPort,
156 listenOptions => listenOptions.Protocols = HttpProtocols.Http1);
159 kestrelOptions.Limits.MaxRequestLineSize = 8400;
164 .SuppressStatusMessages(
true)
166 TimeSpan.FromMinutes(
169 if (updatePath !=
null)
170 hostBuilder.UseContentRoot(
174 return new Server(hostBuilder, updatePath);