* some groups stuff * further groups rework * fixes for pause changes * adjsut timeout interval * fixes and namespace change to file scoped * more fixes * further implement groups * fix change group ownership * add some more stuff for groups * more fixes and additions * some fixes based on analyzers, add shard info to ui * add discord command, cleanup * fix regex * add group migration and deletion on user deletion * add api method for client to check health of connection * adjust regex for vanity * fixes for server and bot * fixes some string comparison in linq queries * fixes group leave and sets alias to null * fix syntax in changeownership * add better logging, fixes for group leaving * fixes for group leave Co-authored-by: Stanley Dimant <root.darkarchon@outlook.com>
66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
using System;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System.Linq;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using MareSynchronosShared.Data;
|
|
using MareSynchronosShared.Metrics;
|
|
|
|
namespace MareSynchronosServer;
|
|
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
var hostBuilder = CreateHostBuilder(args);
|
|
var host = hostBuilder.Build();
|
|
using (var scope = host.Services.CreateScope())
|
|
{
|
|
var services = scope.ServiceProvider;
|
|
using var context = services.GetRequiredService<MareDbContext>();
|
|
|
|
var secondaryServer = Environment.GetEnvironmentVariable("SECONDARY_SERVER");
|
|
if (string.IsNullOrEmpty(secondaryServer) || string.Equals(secondaryServer, "0", StringComparison.Ordinal))
|
|
{
|
|
context.Database.Migrate();
|
|
context.SaveChanges();
|
|
|
|
// clean up residuals
|
|
var looseFiles = context.Files.Where(f => f.Uploaded == false);
|
|
var unfinishedRegistrations = context.LodeStoneAuth.Where(c => c.StartedAt != null);
|
|
context.RemoveRange(unfinishedRegistrations);
|
|
context.RemoveRange(looseFiles);
|
|
context.SaveChanges();
|
|
}
|
|
|
|
var metrics = services.GetRequiredService<MareMetrics>();
|
|
|
|
metrics.SetGaugeTo(MetricsAPI.GaugePairs, context.ClientPairs.Count());
|
|
metrics.SetGaugeTo(MetricsAPI.GaugePairsPaused, context.ClientPairs.Count(p => p.IsPaused));
|
|
}
|
|
|
|
if (args.Length == 0 || !string.Equals(args[0], "dry", StringComparison.Ordinal))
|
|
{
|
|
host.Run();
|
|
}
|
|
}
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.UseSystemd()
|
|
.UseConsoleLifetime()
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseContentRoot(AppContext.BaseDirectory);
|
|
webBuilder.ConfigureLogging((ctx, builder) =>
|
|
{
|
|
builder.AddConfiguration(ctx.Configuration.GetSection("Logging"));
|
|
builder.AddFile(o => o.RootPath = AppContext.BaseDirectory);
|
|
});
|
|
webBuilder.UseStartup<Startup>();
|
|
});
|
|
}
|