DocSpace-buildtools/products/ASC.Projects/Server/Program.cs

86 lines
3.4 KiB
C#
Raw Normal View History

2021-01-26 09:32:31 +00:00
using System;
2021-01-26 09:32:31 +00:00
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
2021-01-26 09:32:31 +00:00
2021-08-08 13:19:54 +00:00
using ASC.Api.Core;
using ASC.Common.Utils;
2021-01-26 09:32:31 +00:00
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace ASC.Projects
{
public class Program
{
public async static Task Main(string[] args)
2021-01-26 09:32:31 +00:00
{
var host = CreateHostBuilder(args).Build();
await host.RunAsync();
2021-01-26 09:32:31 +00:00
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSystemd()
.UseWindowsService()
2021-01-26 09:32:31 +00:00
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder =>
{
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);
}
}
});
2021-01-26 09:32:31 +00:00
})
.ConfigureAppConfiguration((hostingContext, config) =>
{
var buided = config.Build();
var path = buided["pathToConf"];
if (!Path.IsPathRooted(path))
{
path = Path.GetFullPath(CrossPlatform.PathCombine(hostingContext.HostingEnvironment.ContentRootPath, path));
2021-01-26 09:32:31 +00:00
}
config.SetBasePath(path);
config
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
.AddJsonFile("storage.json")
.AddJsonFile("kafka.json")
.AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
.AddJsonFile("rabbitmq.json")
.AddJsonFile($"rabbitmq.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
.AddJsonFile("redis.json")
.AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
2021-01-26 09:32:31 +00:00
.AddEnvironmentVariables()
.AddCommandLine(args)
.AddInMemoryCollection(new Dictionary<string, string>
{
{"pathToConf", path}
});
2021-08-08 13:19:54 +00:00
})
.ConfigureNLogLogging();
2021-01-26 09:32:31 +00:00
}
}