From 3c4344a50432991f74a4d7eb69dac387dbc63e04 Mon Sep 17 00:00:00 2001 From: rootdarkarchon Date: Mon, 12 Dec 2022 10:26:29 +0100 Subject: [PATCH] allow for secondary static files server instances to be spawned --- .../Startup.cs | 41 +++++++++++++------ .../appsettings.json | 3 +- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs b/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs index 307da72..7eec83a 100644 --- a/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs +++ b/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs @@ -35,6 +35,8 @@ public class Startup var mareSettings = Configuration.GetRequiredSection("MareSynchronos"); + bool isSecondary = mareSettings.GetValue("IsSecondaryInstance", false); + var defaultMethodConfig = new MethodConfig { Names = { MethodName.Default }, @@ -48,14 +50,20 @@ public class Startup } }; - services.AddSingleton(); - services.AddSingleton(new MareMetrics(new List { - }, new List - { - MetricsAPI.GaugeFilesTotalSize, - MetricsAPI.GaugeFilesTotal - })); + if (!isSecondary) + { + services.AddSingleton(new MareMetrics(new List + { + }, new List + { + MetricsAPI.GaugeFilesTotalSize, + MetricsAPI.GaugeFilesTotal + })); + services.AddHostedService(); + } + + services.AddSingleton(); services.AddGrpcClient(c => { c.Address = new Uri(mareSettings.GetValue("ServiceAddress")); @@ -73,7 +81,6 @@ public class Startup options.EnableThreadSafetyChecks(false); }, mareSettings.GetValue("DbContextPoolSize", 1024)); - services.AddHostedService(); services.AddHostedService(p => p.GetService()); services.AddAuthentication(options => @@ -91,12 +98,17 @@ public class Startup public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { + bool isSecondary = Configuration.GetSection("MareSynchronos").GetValue("IsSecondaryInstance", false); + app.UseHttpLogging(); app.UseRouting(); - var metricServer = new KestrelMetricServer(4981); - metricServer.Start(); + if (!isSecondary) + { + var metricServer = new KestrelMetricServer(4981); + metricServer.Start(); + } app.UseAuthentication(); app.UseAuthorization(); @@ -108,9 +120,12 @@ public class Startup ServeUnknownFileTypes = true }); - app.UseEndpoints(e => + if (!isSecondary) { - e.MapGrpcService(); - }); + app.UseEndpoints(e => + { + e.MapGrpcService(); + }); + } } } \ No newline at end of file diff --git a/MareSynchronosServer/MareSynchronosStaticFilesServer/appsettings.json b/MareSynchronosServer/MareSynchronosStaticFilesServer/appsettings.json index 63c89c8..75889bc 100644 --- a/MareSynchronosServer/MareSynchronosStaticFilesServer/appsettings.json +++ b/MareSynchronosServer/MareSynchronosStaticFilesServer/appsettings.json @@ -23,7 +23,8 @@ "CacheSizeHardLimitInGiB": -1, "UnusedFileRetentionPeriodInDays": 7, "CacheDirectory": "G:\\ServerTest", - "ServiceAddress": "http://localhost:5002" + "ServiceAddress": "http://localhost:5002", + "IsSecondaryInstance": "false" }, "AllowedHosts": "*" }