allow for secondary static files server instances to be spawned

This commit is contained in:
rootdarkarchon
2022-12-12 10:26:29 +01:00
parent 80de0923fe
commit 3c4344a504
2 changed files with 30 additions and 14 deletions

View File

@@ -35,6 +35,8 @@ public class Startup
var mareSettings = Configuration.GetRequiredSection("MareSynchronos"); var mareSettings = Configuration.GetRequiredSection("MareSynchronos");
bool isSecondary = mareSettings.GetValue<bool>("IsSecondaryInstance", false);
var defaultMethodConfig = new MethodConfig var defaultMethodConfig = new MethodConfig
{ {
Names = { MethodName.Default }, Names = { MethodName.Default },
@@ -48,14 +50,20 @@ public class Startup
} }
}; };
services.AddSingleton<GrpcAuthenticationService>();
services.AddSingleton(new MareMetrics(new List<string> {
}, new List<string>
{
MetricsAPI.GaugeFilesTotalSize,
MetricsAPI.GaugeFilesTotal
}));
if (!isSecondary)
{
services.AddSingleton(new MareMetrics(new List<string>
{
}, new List<string>
{
MetricsAPI.GaugeFilesTotalSize,
MetricsAPI.GaugeFilesTotal
}));
services.AddHostedService<CleanupService>();
}
services.AddSingleton<GrpcAuthenticationService>();
services.AddGrpcClient<AuthService.AuthServiceClient>(c => services.AddGrpcClient<AuthService.AuthServiceClient>(c =>
{ {
c.Address = new Uri(mareSettings.GetValue<string>("ServiceAddress")); c.Address = new Uri(mareSettings.GetValue<string>("ServiceAddress"));
@@ -73,7 +81,6 @@ public class Startup
options.EnableThreadSafetyChecks(false); options.EnableThreadSafetyChecks(false);
}, mareSettings.GetValue("DbContextPoolSize", 1024)); }, mareSettings.GetValue("DbContextPoolSize", 1024));
services.AddHostedService<CleanupService>();
services.AddHostedService(p => p.GetService<GrpcAuthenticationService>()); services.AddHostedService(p => p.GetService<GrpcAuthenticationService>());
services.AddAuthentication(options => services.AddAuthentication(options =>
@@ -91,12 +98,17 @@ public class Startup
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ {
bool isSecondary = Configuration.GetSection("MareSynchronos").GetValue<bool>("IsSecondaryInstance", false);
app.UseHttpLogging(); app.UseHttpLogging();
app.UseRouting(); app.UseRouting();
var metricServer = new KestrelMetricServer(4981); if (!isSecondary)
metricServer.Start(); {
var metricServer = new KestrelMetricServer(4981);
metricServer.Start();
}
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
@@ -108,9 +120,12 @@ public class Startup
ServeUnknownFileTypes = true ServeUnknownFileTypes = true
}); });
app.UseEndpoints(e => if (!isSecondary)
{ {
e.MapGrpcService<FileService>(); app.UseEndpoints(e =>
}); {
e.MapGrpcService<FileService>();
});
}
} }
} }

View File

@@ -23,7 +23,8 @@
"CacheSizeHardLimitInGiB": -1, "CacheSizeHardLimitInGiB": -1,
"UnusedFileRetentionPeriodInDays": 7, "UnusedFileRetentionPeriodInDays": 7,
"CacheDirectory": "G:\\ServerTest", "CacheDirectory": "G:\\ServerTest",
"ServiceAddress": "http://localhost:5002" "ServiceAddress": "http://localhost:5002",
"IsSecondaryInstance": "false"
}, },
"AllowedHosts": "*" "AllowedHosts": "*"
} }