Exemplo n.º 1
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .UseSystemd()
        .ConfigureAppConfiguration((hostContext, config) =>
        {
            // see chmod(2), https://linux.die.net/man/2/chmod for reference
            FilePermissions root600 =
                FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IFREG;
            FilePermissions root640 =
                FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IFREG;

            if (File.Exists("/etc/EchoSeven/appsettings.json") &&
                UnixFileSystemInfo.GetFileSystemEntry("/etc/EchoSeven/appsettings.json").OwnerUser.UserName.Equals("root") &&
                UnixFileSystemInfo.GetFileSystemEntry("/etc/EchoSeven/appsettings.json").OwnerGroup.GroupName.Equals("root") &&
                (UnixFileSystemInfo.GetFileSystemEntry("/etc/EchoSeven/appsettings.json").Protection.Equals(root600) ||
                 UnixFileSystemInfo.GetFileSystemEntry("/etc/EchoSeven/appsettings.json").Protection.Equals(root640)) &&
                UnixEnvironment.EffectiveUser.UserName.Equals("root"))
            {
                var settings = config.Build();
                config.AddJsonFile("/etc/EchoSeven/appsettings.json", optional: true, reloadOnChange: false);
            }
        })
        .ConfigureServices((hostContext, services) =>
        {
            IConfiguration configuration = hostContext.Configuration;
            EchoServerOptions options    = configuration.GetSection("EchoService").Get <EchoServerOptions>();
            services.AddSingleton(options);
            services.AddHostedService <EchoSevenService>();
        });
Exemplo n.º 2
0
 public EchoSevenService(ILogger <EchoSevenService> logger, EchoServerOptions options)
 {
     _logger  = logger;
     _options = options;
 }