Beispiel #1
0
        public static void Configure(HostConfigurator config)
        {
            // http://docs.topshelf-project.com/en/latest/
            Logger.Debug("Configuring windows service");
            config.Service <WindowsService>(ConfigureServiceClass);

            // prompt for credentials - Sys Admins will need to type password for SchTasks.Admin user
            config.RunAsPrompt();

            config.SetDescription("Cyrus MicroServices Background Processing (Multiple Mini-Apps)");
            config.SetDisplayName("Cyrus MicroServices");
            config.SetServiceName("Cyrus.MicroServices");

            //TODO: windows service settings
            //config.SetDescription(AppSettings.Default.WindowsService.Description);
            //config.SetDisplayName(AppSettings.Default.WindowsService.DisplayName);
            //config.SetServiceName(AppSettings.Default.WindowsService.Name);

            config.StartAutomatically();
            config.UseNLog();

            config.EnableServiceRecovery(rc =>
            {
                rc.RestartService(delayInMinutes: 2);
                //rc.RestartService(AppSettings.Default.WindowsService.RecoverRestartAfterMins);
            });

            Logger.Debug("Windows service configured");
        }
        public static void Configure(HostConfigurator config)
        {
            // http://docs.topshelf-project.com/en/latest/
            Logger.Debug("Configuring windows service");
            config.Service<WindowsService>(ConfigureServiceClass);

            // prompt for credentials - Sys Admins will need to type password for SchTasks.Admin user
            config.RunAsPrompt();

            config.SetDescription("Cyrus MicroServices Background Processing (Multiple Mini-Apps)");
            config.SetDisplayName("Cyrus MicroServices");
            config.SetServiceName("Cyrus.MicroServices");

            //TODO: windows service settings
            //config.SetDescription(AppSettings.Default.WindowsService.Description);
            //config.SetDisplayName(AppSettings.Default.WindowsService.DisplayName);
            //config.SetServiceName(AppSettings.Default.WindowsService.Name);

            config.StartAutomatically();
            config.UseNLog();

            config.EnableServiceRecovery(rc =>
            {
                rc.RestartService(delayInMinutes: 2);
                //rc.RestartService(AppSettings.Default.WindowsService.RecoverRestartAfterMins);
            });

            Logger.Debug("Windows service configured");
        }
        private static void ConfigureService(HostConfigurator x)
        {
            x.StartAutomatically();

            x.SetServiceName(GetSettings().GetValue <string>("ServiceName"));
            x.SetDisplayName(GetSettings().GetValue <string>("ServiceName"));
            x.SetDescription(GetSettings().GetValue <string>("ServiceDescription"));

            x.EnableServiceRecovery(r =>
            {
                r.RestartService(0);
                r.OnCrashOnly();
                r.SetResetPeriod(1);
            });
        }
Beispiel #4
0
        public static void ConfigureTownCrierService(this HostConfigurator config, Func <ITownCrier> townCrierFactory)
        {
            config.EnableServiceRecovery(rc =>
            {
                rc.RestartService(1);
                rc.SetResetPeriod(7);
            });

            config.EnablePauseAndContinue();
            config.EnableShutdown();

            config.Service <ITownCrier>(s =>
            {
                s.ConstructUsing(name => townCrierFactory());
                s.WhenStarted(tc =>
                {
                    Log.Information("Starting...");
                    TownCrier = tc;
                    SystemEvents.PowerModeChanged += OnPowerChange;
                    tc.Start();
                });
                s.WhenStopped(tc =>
                {
                    Log.Information("Stopping...");
                    TownCrier = tc;
                    SystemEvents.PowerModeChanged -= OnPowerChange;
                    tc.Stop();
                });
                s.WhenPaused(tc =>
                {
                    Log.Information("Pausing...");
                    TownCrier = tc;
                    SystemEvents.PowerModeChanged -= OnPowerChange;
                    tc.Stop();
                });

                s.WhenContinued(tc =>
                {
                    Log.Information("Continuing...");
                    TownCrier = tc;
                    SystemEvents.PowerModeChanged += OnPowerChange;
                    tc.Start();
                });

                s.WhenShutdown(tc =>
                {
                    Log.Information("Shutting down...");
                    TownCrier = tc;
                    SystemEvents.PowerModeChanged -= OnPowerChange;
                    tc.Stop();
                });

                s.WhenPowerEvent((service, args) =>
                {
                    Log.Information($"PowerEvent ({args.EventCode})");
                    return(false);
                });
            });

            config.RunAsLocalSystem();
            config.StartAutomatically();
        }