Exemple #1
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .UseServiceProviderFactory(new AutofacServiceProviderFactory())
        .ConfigureWebHostDefaults(whb => whb

                                  .UseConfiguration(InitUtils.BuildConfiguration(args).Build())
                                  .ConfigureKestrel(opts => { opts.ListenAnyIP(5000); })
                                  .UseStartup <Startup>());
Exemple #2
0
 public void ConfigureContainer(ContainerBuilder builder)
 {
     builder.RegisterInstance(InitUtils.BuildConfiguration(Environment.GetCommandLineArgs()).Build())
     .As <IConfiguration>();
     builder.RegisterModule(new ConfigModule <ApiConfig>("API"));
     builder.RegisterModule(new LoggingModule("api"));
     builder.RegisterModule(new MetricsModule("API"));
     builder.RegisterModule <DataStoreModule>();
     builder.RegisterModule <APIModule>();
 }
Exemple #3
0
 public static IHostBuilder CreateHostBuilder(string[] args) =>
 Host.CreateDefaultBuilder(args)
 .UseServiceProviderFactory(new AutofacServiceProviderFactory())
 .UseSerilog()
 .ConfigureWebHostDefaults(whb => whb
                           .UseConfiguration(InitUtils.BuildConfiguration(args).Build())
                           .ConfigureKestrel(opts =>
 {
     opts.ListenAnyIP(opts.ApplicationServices.GetRequiredService <ApiConfig>().Port);
 })
                           .UseStartup <Startup>());
Exemple #4
0
 public void ConfigureContainer(ContainerBuilder builder)
 {
     builder.RegisterInstance(InitUtils.BuildConfiguration(Environment.GetCommandLineArgs()).Build())
     .As <IConfiguration>();
     builder.RegisterModule(new ConfigModule <ApiConfig>("API"));
     builder.RegisterModule(new LoggingModule("api",
                                              cfg: new LoggerConfiguration().Filter.ByExcluding(exc => exc.Exception is PKError || exc.Exception.IsUserError())));
     builder.RegisterModule(new MetricsModule("API"));
     builder.RegisterModule <DataStoreModule>();
     builder.RegisterModule <APIModule>();
 }
Exemple #5
0
        static Task Main(string[] args)
        {
            // Load configuration and run global init stuff
            var config = InitUtils.BuildConfiguration(args).Build();

            InitUtils.InitStatic();

            // Set up DI container and modules
            var services = BuildContainer(config);

            return(RunWrapper(services, async ct =>
            {
                var logger = services.Resolve <ILogger>().ForContext <Init>();

                // Initialize Sentry SDK, and make sure it gets dropped at the end
                using var _ = Sentry.SentrySdk.Init(services.Resolve <CoreConfig>().SentryUrl);

                // "Connect to the database" (ie. set off database migrations and ensure state)
                logger.Information("Connecting to database");
                await services.Resolve <IDatabase>().ApplyMigrations();

                // Init the bot instance itself, register handlers and such to the client before beginning to connect
                logger.Information("Initializing bot");
                var bot = services.Resolve <Bot>();
                bot.Init();

                // Install observer for request/responses
                DiscordRequestObserver.Install(services);

                // Start the Discord shards themselves (handlers already set up)
                logger.Information("Connecting to Discord");
                var info = await services.Resolve <DiscordApiClient>().GetGatewayBot();
                await services.Resolve <Cluster>().Start(info);
                logger.Information("Connected! All is good (probably).");

                // Lastly, we just... wait. Everything else is handled in the DiscordClient event loop
                try
                {
                    await Task.Delay(-1, ct);
                }
                catch (TaskCanceledException)
                {
                    // Once the CancellationToken fires, we need to shut stuff down
                    // (generally happens given a SIGINT/SIGKILL/Ctrl-C, see calling wrapper)
                    await bot.Shutdown();
                }
            }));
        }
Exemple #6
0
    private static async Task Main(string[] args)
    {
        // Load configuration and run global init stuff
        var config = InitUtils.BuildConfiguration(args).Build();

        InitUtils.InitStatic();

        await BuildInfoService.LoadVersion();

        var services = BuildContainer(config);

        var cfg = services.Resolve <CoreConfig>();

        if (cfg.UseRedisMetrics)
        {
            await services.Resolve <RedisService>().InitAsync(cfg);
        }

        services.Resolve <TaskHandler>().Run();

        await Task.Delay(-1);
    }
Exemple #7
0
 public static IHostBuilder CreateHostBuilder(string[] args) =>
 Host.CreateDefaultBuilder(args)
 .ConfigureMetrics(_metrics)
 .UseMetricsWebTracking()
 .UseMetricsEndpoints()
 .UseMetrics(
     options =>
 {
     options.EndpointOptions = endpointsOptions =>
     {
         endpointsOptions.MetricsTextEndpointOutputFormatter = _metrics.OutputMetricsFormatters.OfType <MetricsPrometheusTextOutputFormatter>().First();
         endpointsOptions.MetricsEndpointOutputFormatter     = _metrics.OutputMetricsFormatters.OfType <MetricsPrometheusProtobufOutputFormatter>().First();
     };
 })
 .UseServiceProviderFactory(new AutofacServiceProviderFactory())
 .UseSerilog()
 .ConfigureWebHostDefaults(whb => whb
                           .UseConfiguration(InitUtils.BuildConfiguration(args).Build())
                           .ConfigureKestrel(opts =>
 {
     opts.ListenAnyIP(opts.ApplicationServices.GetRequiredService <ApiConfig>().Port);
 })
                           .UseStartup <Startup>());
Exemple #8
0
    private static async Task Main(string[] args)
    {
        // Load configuration and run global init stuff
        var config = InitUtils.BuildConfiguration(args).Build();

        InitUtils.InitStatic();

        // init version service
        await BuildInfoService.LoadVersion();

        // Set up DI container and modules
        var services = BuildContainer(config);

        await RunWrapper(services, async ct =>
        {
            var logger = services.Resolve <ILogger>().ForContext <Init>();

            // Initialize Sentry SDK, and make sure it gets dropped at the end

            using var _ = SentrySdk.Init(opts =>
            {
                opts.Dsn                 = services.Resolve <CoreConfig>().SentryUrl;
                opts.Release             = BuildInfoService.FullVersion;
                opts.AutoSessionTracking = true;
                opts.DisableTaskUnobservedTaskExceptionCapture();
            });

            var config     = services.Resolve <BotConfig>();
            var coreConfig = services.Resolve <CoreConfig>();

            // initialize Redis
            var redis = services.Resolve <RedisService>();
            if (config.UseRedisRatelimiter)
            {
                await redis.InitAsync(coreConfig);
            }

            if (config.Cluster == null)
            {
                // "Connect to the database" (ie. set off database migrations and ensure state)
                logger.Information("Connecting to database");
                await services.Resolve <IDatabase>().ApplyMigrations();

                // Clear shard status from Redis
                if (redis.Connection != null)
                {
                    await redis.Connection.GetDatabase().KeyDeleteAsync("pluralkit:shardstatus");
                }
            }

            // Init the bot instance itself, register handlers and such to the client before beginning to connect
            logger.Information("Initializing bot");
            var bot = services.Resolve <Bot>();
            bot.Init();


            // Start the Discord shards themselves (handlers already set up)
            logger.Information("Connecting to Discord");
            await StartCluster(services);
            logger.Information("Connected! All is good (probably).");

            // Lastly, we just... wait. Everything else is handled in the DiscordClient event loop
            try
            {
                await Task.Delay(-1, ct);
            }
            catch (TaskCanceledException)
            {
                // Once the CancellationToken fires, we need to shut stuff down
                // (generally happens given a SIGINT/SIGKILL/Ctrl-C, see calling wrapper)
                await bot.Shutdown();
            }
        });
    }
Exemple #9
0
        static void Main(string[] args) => new Initialize
        {
            _config = InitUtils.BuildConfiguration(args).Build()
        }

        .MainAsync().GetAwaiter().GetResult();
Exemple #10
0
 public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 WebHost.CreateDefaultBuilder(args)
 .UseConfiguration(InitUtils.BuildConfiguration(args).Build())
 .ConfigureKestrel(opts => { opts.ListenAnyIP(5000); })
 .UseStartup <Startup>();