2021-08-31 09:40:28 +00:00
|
|
|
|
using System;
|
2021-04-23 13:54:12 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-06-08 08:17:54 +00:00
|
|
|
|
using System.IO;
|
2021-08-31 09:40:28 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
using ASC.Api.Core;
|
|
|
|
|
using ASC.Common.Utils;
|
|
|
|
|
|
|
|
|
|
using Autofac.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-06-03 09:15:05 +00:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
namespace ASC.Data.Backup
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
2021-08-31 09:40:28 +00:00
|
|
|
|
{
|
2021-04-23 13:54:12 +00:00
|
|
|
|
public async static Task Main(string[] args)
|
2021-08-31 09:40:28 +00:00
|
|
|
|
{
|
|
|
|
|
var host = CreateHostBuilder(args).Build();
|
|
|
|
|
|
2021-04-23 13:54:12 +00:00
|
|
|
|
await host.RunAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-22 13:10:37 +00:00
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
2021-08-31 09:40:28 +00:00
|
|
|
|
Host.CreateDefaultBuilder(args)
|
|
|
|
|
.UseSystemd()
|
2021-11-25 13:48:08 +00:00
|
|
|
|
.UseWindowsService()
|
2020-11-02 16:27:08 +00:00
|
|
|
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
2020-06-23 10:48:36 +00:00
|
|
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
|
|
|
{
|
2021-08-31 09:40:28 +00:00
|
|
|
|
var builder = webBuilder.UseStartup<Startup>();
|
|
|
|
|
|
|
|
|
|
builder.ConfigureKestrel((hostingContext, serverOptions) =>
|
|
|
|
|
{
|
|
|
|
|
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
|
|
|
|
|
|
|
|
|
|
if (!kestrelConfig.Exists()) return;
|
|
|
|
|
|
|
|
|
|
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
|
|
|
|
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrWhiteSpace(unixSocket))
|
|
|
|
|
{
|
|
|
|
|
unixSocket = String.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
|
|
|
|
|
|
|
|
|
|
serverOptions.ListenUnixSocket(unixSocket);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-06-23 10:48:36 +00:00
|
|
|
|
})
|
2020-06-03 09:15:05 +00:00
|
|
|
|
.ConfigureAppConfiguration((hostContext, config) =>
|
|
|
|
|
{
|
|
|
|
|
var buided = config.Build();
|
|
|
|
|
var path = buided["pathToConf"];
|
|
|
|
|
if (!Path.IsPathRooted(path))
|
|
|
|
|
{
|
2021-04-16 13:26:26 +00:00
|
|
|
|
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
2020-06-03 09:15:05 +00:00
|
|
|
|
}
|
2020-10-12 19:39:23 +00:00
|
|
|
|
config.SetBasePath(path);
|
2020-06-03 09:15:05 +00:00
|
|
|
|
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
|
2020-10-12 19:39:23 +00:00
|
|
|
|
config
|
2020-06-03 09:15:05 +00:00
|
|
|
|
.AddJsonFile("appsettings.json")
|
|
|
|
|
.AddJsonFile($"appsettings.{env}.json", true)
|
|
|
|
|
.AddJsonFile("storage.json")
|
|
|
|
|
.AddJsonFile("notify.json")
|
2021-09-03 15:04:06 +00:00
|
|
|
|
.AddJsonFile($"notify.{env}.json", true)
|
2020-06-03 09:15:05 +00:00
|
|
|
|
.AddJsonFile("backup.json")
|
|
|
|
|
.AddJsonFile("kafka.json")
|
|
|
|
|
.AddJsonFile($"kafka.{env}.json", true)
|
2021-10-26 17:09:19 +00:00
|
|
|
|
.AddEnvironmentVariables()
|
|
|
|
|
.AddCommandLine(args)
|
2020-11-26 17:30:57 +00:00
|
|
|
|
.AddInMemoryCollection(new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{"pathToConf", path }
|
|
|
|
|
}
|
|
|
|
|
);
|
2021-08-31 09:40:28 +00:00
|
|
|
|
})
|
|
|
|
|
.ConfigureNLogLogging();
|
2021-04-23 13:54:12 +00:00
|
|
|
|
|
2020-06-03 09:15:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|