2021-04-23 13:54:12 +00:00
|
|
|
using System;
|
2019-11-15 08:47:56 +00:00
|
|
|
using System.Collections.Generic;
|
2019-06-21 08:03:42 +00:00
|
|
|
using System.IO;
|
2021-04-23 13:54:12 +00:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Threading.Tasks;
|
2019-12-20 11:17:01 +00:00
|
|
|
|
2021-08-08 13:19:54 +00:00
|
|
|
using ASC.Api.Core;
|
2021-04-16 13:26:26 +00:00
|
|
|
using ASC.Common.Utils;
|
|
|
|
|
2020-11-02 16:27:08 +00:00
|
|
|
using Autofac.Extensions.DependencyInjection;
|
|
|
|
|
2019-05-15 14:56:09 +00:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2019-06-11 08:26:40 +00:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2019-05-15 14:56:09 +00:00
|
|
|
|
|
|
|
namespace ASC.Web.Studio
|
|
|
|
{
|
|
|
|
public class Program
|
|
|
|
{
|
2021-04-23 13:54:12 +00:00
|
|
|
public async static Task Main(string[] args)
|
|
|
|
{
|
|
|
|
var host = CreateHostBuilder(args).Build();
|
|
|
|
|
|
|
|
await host.RunAsync();
|
2019-05-15 14:56:09 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 13:54:12 +00:00
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
|
|
Host.CreateDefaultBuilder(args)
|
|
|
|
.UseSystemd()
|
|
|
|
.UseWindowsService()
|
2020-11-02 16:27:08 +00:00
|
|
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
2021-04-23 13:54:12 +00:00
|
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
2019-06-11 08:26:40 +00:00
|
|
|
{
|
2021-04-23 13:54:12 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-06-11 08:26:40 +00:00
|
|
|
})
|
2019-08-15 12:04:42 +00:00
|
|
|
.ConfigureAppConfiguration((hostingContext, config) =>
|
|
|
|
{
|
2020-10-12 16:23:15 +00:00
|
|
|
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(hostingContext.HostingEnvironment.ContentRootPath, path));
|
2020-10-12 16:23:15 +00:00
|
|
|
}
|
2020-10-12 19:39:23 +00:00
|
|
|
config.SetBasePath(path);
|
|
|
|
config
|
2020-10-12 16:23:15 +00:00
|
|
|
.AddJsonFile("appsettings.json")
|
|
|
|
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
|
|
|
|
.AddJsonFile("storage.json")
|
|
|
|
.AddJsonFile("kafka.json")
|
|
|
|
.AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
|
|
|
|
.AddEnvironmentVariables()
|
2020-11-26 17:30:57 +00:00
|
|
|
.AddCommandLine(args)
|
|
|
|
.AddInMemoryCollection(new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{"pathToConf", path }
|
|
|
|
}
|
|
|
|
);
|
2021-04-23 13:54:12 +00:00
|
|
|
|
2021-08-08 13:19:54 +00:00
|
|
|
})
|
|
|
|
.ConfigureNLogLogging();
|
2019-05-15 14:56:09 +00:00
|
|
|
}
|
|
|
|
}
|