allow for secondary static files server instances to be spawned
This commit is contained in:
		| @@ -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> { |         if (!isSecondary) | ||||||
|  |         { | ||||||
|  |             services.AddSingleton(new MareMetrics(new List<string> | ||||||
|  |             { | ||||||
|             }, new List<string> |             }, new List<string> | ||||||
|             { |             { | ||||||
|                 MetricsAPI.GaugeFilesTotalSize, |                 MetricsAPI.GaugeFilesTotalSize, | ||||||
|                 MetricsAPI.GaugeFilesTotal |                 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(); | ||||||
|  |  | ||||||
|  |         if (!isSecondary) | ||||||
|  |         { | ||||||
|             var metricServer = new KestrelMetricServer(4981); |             var metricServer = new KestrelMetricServer(4981); | ||||||
|             metricServer.Start(); |             metricServer.Start(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         app.UseAuthentication(); |         app.UseAuthentication(); | ||||||
|         app.UseAuthorization(); |         app.UseAuthorization(); | ||||||
| @@ -108,9 +120,12 @@ public class Startup | |||||||
|             ServeUnknownFileTypes = true |             ServeUnknownFileTypes = true | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|  |         if (!isSecondary) | ||||||
|  |         { | ||||||
|             app.UseEndpoints(e => |             app.UseEndpoints(e => | ||||||
|             { |             { | ||||||
|                 e.MapGrpcService<FileService>(); |                 e.MapGrpcService<FileService>(); | ||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
| @@ -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": "*" | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 rootdarkarchon
					rootdarkarchon