예제 #1
0
        static void ConfigureHost(HostConfigurator x)
        {
            x.UseSerilog();
            x.Service <ILifetimeScope>(
                s =>
            {
                s.ConstructUsing(serviceFactory => _container.BeginLifetimeScope());
                s.WhenStarted(scope => Task.Run(async() =>
                {
                    try
                    {
                        await scope.Resolve <PapercutServerService>().Start();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "Exception Caught Running Service");
                    }
                }));
                s.WhenStopped(scope => scope.Resolve <PapercutServerService>().Stop().Wait());
                s.WhenShutdown(scope => scope.Dispose());
            });

            x.RunAsLocalSystem();

            x.SetDescription("Papercut SMTP Backend Service");
            x.SetDisplayName("Papercut SMTP Service");
            x.SetServiceName("PapercutServerService");
        }
예제 #2
0
        private static void InitService(HostConfigurator config, ILifetimeScope container)
        {
            config.UseAutofacContainer(container);

            config.Service <MediaIndexingService>(sc =>
            {
                sc.ConstructUsingAutofacContainer();
                sc.WhenStarted(s => s.Start());
                sc.WhenStopped(s => s.Stop());

                sc.WebApiEndpoint(api => api
                                  .OnLocalhost() // defaults to port 8080
                                  .ConfigureServer(c => c.MapHttpAttributeRoutes())
                                  .UseDependencyResolver(new AutofacWebApiDependencyResolver(container)));
            });

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

            config.SetDescription("Media indexing service for indexing images and videos");
            config.SetDisplayName("Media Indexing Service");
            config.SetServiceName("MediaIndexingService");

            config.UseLog4Net();
        }
예제 #3
0
        private void SetServiceRunAs(HostConfigurator x)
        {
            switch (ServiceRunAs)
            {
            case ServiceRunAs.LocalService:
                x.RunAsLocalService();
                break;

            case ServiceRunAs.LocalSystem:
                x.RunAsLocalSystem();
                break;

            case ServiceRunAs.NetworkService:
                x.RunAsNetworkService();
                break;

            case ServiceRunAs.Prompt:
                x.RunAsPrompt();
                break;

            case ServiceRunAs.UserLogin:
                x.RunAs(UserName, UserPassword);
                break;
            }
        }
예제 #4
0
        private static void ConfigureHost(HostConfigurator x)
        {
            x.Service <WindowsService>(ConfigureService);

            x.SetServiceName(Name);
            x.SetDisplayName(Name);
            x.SetDescription(Name);

            x.RunAsLocalSystem();
            x.StartAutomatically();
            x.OnException(ex => HostLogger.Get(Name).Error(ex));
        }
예제 #5
0
        static void Configurator(HostConfigurator configurator)
        {
            configurator.Service<ServiceHost>(settings =>
                                                  {
                                                      settings.ConstructUsing(p=> new ServiceHost());
                                                      settings.WhenStarted(p=>p.Start());
                                                      settings.WhenStopped(p=>p.Stop());
                                                  });

            configurator.SetServiceName("Listener");
            configurator.SetDisplayName("DeployNowListener");
            configurator.RunAsLocalSystem();
            configurator.StartAutomaticallyDelayed();
        }
        public void Configure(HostConfigurator config)
        {
            config.Service <LeitorService>((s) =>
            {
                s.ConstructUsing(name => new LeitorService());
                s.WhenStarted(app => app.Start());
                s.WhenStopped(app => app.Stop());
            });

            config.RunAsLocalSystem();
            config.SetDescription("Serviço responsável por enviar para o banco de dados as leituras do Field Logger");
            config.SetDisplayName("FieldLogger.Service");
            config.SetServiceName("FieldLogger.Service");
        }
예제 #7
0
        private static void HostConfiguration(HostConfigurator configurator)
        {
            configurator.Service <IService>(service =>
            {
                service.ConstructUsing(s => new AutomaticRepositoryBuildService());
                service.WhenStarted(s => s.Start());
                service.WhenStopped(s => s.Stop());
            });

            configurator.RunAsLocalSystem();
            configurator.SetServiceName("AutomaticRepositoryBuildService");
            configurator.SetDisplayName("Automatic Repository Build Service");
            configurator.SetDescription("Service used to automatically build an Arma3Sync Repository.");
        }
예제 #8
0
        private static void ConfigureService(HostConfigurator x, IContainer container)
        {
            x.Service <ServiceControl>(s =>
            {
                s.ConstructUsing(name => container.Resolve <ServiceControl>());
                s.WhenStarted((sc, hc) => sc.Start(hc));
                s.WhenStopped((sc, hc) => sc.Stop(hc));
            });
            x.RunAsLocalSystem();

            x.SetDescription("Rambo");
            x.SetDisplayName("Rambo");
            x.SetServiceName("Rambo");

            //x.AfterInstall(InstallPerfCounters);
            //x.BeforeUninstall(UninstallPerfCounters);
        }
예제 #9
0
        void ConfigureHost(HostConfigurator x)
        {
            x.UseSerilog(_container.Resolve<ILogger>());
            x.Service<PapercutServerService>(
                s =>
                {
                    s.ConstructUsing(serviceFactory => _container.Resolve<PapercutServerService>());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                    s.WhenShutdown(ts => _container.Dispose());
                });

            x.RunAsLocalSystem();

            x.SetDescription("Papercut SMTP Backend Service");
            x.SetDisplayName("Papercut SMTP Service");
            x.SetServiceName("PapercutServerService");
        }
예제 #10
0
        static void ConfigureHost(HostConfigurator x)
        {
            x.UseSerilog();
            x.Service <ILifetimeScope>(
                s =>
            {
                s.ConstructUsing(serviceFactory => _container.BeginLifetimeScope());
                s.WhenStarted(scope => scope.Resolve <PapercutServerService>().Start());
                s.WhenStopped(scope => scope.Resolve <PapercutServerService>().Stop());
                s.WhenShutdown(scope => scope.Dispose());
            });

            x.RunAsLocalSystem();

            x.SetDescription("Papercut SMTP Backend Service");
            x.SetDisplayName("Papercut SMTP Service");
            x.SetServiceName("PapercutServerService");
        }
예제 #11
0
        void ConfigureHost(HostConfigurator x)
        {
            x.UseSerilog(_container.Resolve <ILogger>());
            x.Service <PapercutServerService>(
                s =>
            {
                s.ConstructUsing(serviceFactory => _container.Resolve <PapercutServerService>());
                s.WhenStarted(tc => tc.Start());
                s.WhenStopped(tc => tc.Stop());
                s.WhenShutdown(ts => _container.Dispose());
            });

            x.RunAsLocalSystem();

            x.SetDescription("Papercut SMTP Backend Service");
            x.SetDisplayName("Papercut SMTP Service");
            x.SetServiceName("PapercutServerService");
        }
예제 #12
0
        private static void SetRunAs(HostConfigurator host, T businessService)
        {
            switch (businessService.RunAs)
            {
            case ServiceRunAs.LocalService:
                host.RunAsLocalService();
                break;

            case ServiceRunAs.LocalSystem:
                host.RunAsLocalSystem();
                break;

            case ServiceRunAs.NetworkService:
                host.RunAsNetworkService();
                break;

            case ServiceRunAs.Prompt:
                host.RunAsPrompt();
                break;
            }
        }
        private void Configure(HostConfigurator config)
        {
            config.Service <ISelfUpdatableService>(service =>
            {
                service.ConstructUsing(settings => selfUpdatableService);

                service.WhenStarted((s, hostControl) =>
                {
                    s.Start();
                    return(true);
                });

                service.AfterStartingService(() => { updater?.Start(); });

                service.WhenStopped(s => { s.Stop(); });
            });

            config.SetServiceName(serviceName);
            config.SetDisplayName(serviceDisplayName);
            config.StartAutomatically();
            config.EnableShutdown();

            if (promtCredsWhileInstall)
            {
                config.RunAsFirstPrompt();
            }
            else
            {
                config.RunAsLocalSystem();
            }

            config.AddCommandLineSwitch("squirrel", _ => { });
            config.AddCommandLineDefinition("firstrun", _ => Environment.Exit(0));
            config.AddCommandLineDefinition("obsolete", _ => Environment.Exit(0));
            config.AddCommandLineDefinition("updated", version => { config.UseHostBuilder((env, settings) => new UpdateHostBuilder(env, settings, version, withOverlapping)); });
            config.AddCommandLineDefinition("install", version => { config.UseHostBuilder((env, settings) => new InstallAndStartHostBuilder(env, settings, version)); });
            config.AddCommandLineDefinition("uninstall", _ => { config.UseHostBuilder((env, settings) => new StopAndUninstallHostBuilder(env, settings)); });
        }
예제 #14
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();
        }
예제 #15
0
        /// <summary>
        /// Configure
        /// </summary>
        /// <param name="hostCfg"></param>
        /// <returns></returns>
        public HostConfigurator Configure(ref HostConfigurator hostCfg)
        {
            #region 设置运行模式

            switch (RunAs)
            {
            case ServiceAccount.LocalService:
                hostCfg.RunAsLocalService();
                break;

            case ServiceAccount.LocalSystem:
                hostCfg.RunAsLocalSystem();
                break;

            case ServiceAccount.NetworkService:
                hostCfg.RunAsNetworkService();
                break;

            case ServiceAccount.User:
                hostCfg.RunAs(UserName, Password);
                break;

            default:
                hostCfg.RunAsPrompt();
                break;
            }

            #endregion

            #region 设置启动模式

            switch (StartMode)
            {
            case HostStartMode.AutomaticDelayed:
                hostCfg.StartAutomaticallyDelayed();
                break;

            case HostStartMode.Disabled:
                break;

            case HostStartMode.Manual:
                hostCfg.StartManually();
                break;

            default:
                hostCfg.StartAutomatically();
                break;
            }

            #endregion

            #region 设置服务基础信息

            hostCfg.SetServiceName(ServiceName);
            hostCfg.SetInstanceName(InstanceName);
            hostCfg.SetDescription(ServiceDescription);
            hostCfg.SetDisplayName(ServiceDisplayName);

            #endregion
            return(hostCfg);
        }
 public override void Configure(HostConfigurator conf)
 {
     conf.RunAsLocalSystem();
 }
예제 #17
0
 public void ApplyTo(HostConfigurator configurator)
 {
     configurator.RunAsLocalSystem();
 }
예제 #18
0
        /// <summary>
        /// Configures the specified configuration.
        /// </summary>
        /// <param name="config">The configuration.</param>
        private void Configure(HostConfigurator config)
        {
            try
            {
                config.Service <ISelfUpdatableService>(service =>
                {
                    service.ConstructUsing(settings => selfUpdatableService);
                    service.WhenStarted((s, hostControl) =>
                    {
                        s.Start();
                        return(true);
                    });
                    service.AfterStartingService(() => { updater?.Start(); });
                    service.WhenStopped(s => { s.Stop(); });
                });
                config.StartAutomatically();
                config.EnableShutdown();
                config.UseAssemblyInfoForServiceInfo(HostAssembly);
                if (promptForCredentialsWhileInstalling)
                {
                    config.RunAsFirstPrompt();
                }
                else
                {
                    if (TypeRunAs == RunAS.LocalSystem)
                    {
                        config.RunAsLocalSystem();
                    }
                    else if (TypeRunAs == RunAS.LocalService)
                    {
                        config.RunAsLocalService();
                    }
                    else if (TypeRunAs == RunAS.NetworkService)
                    {
                        config.RunAsNetworkService();
                    }
                    else if (TypeRunAs == RunAS.SpecificUser)
                    {
                        if (string.IsNullOrEmpty(serviceLogin))
                        {
                            throw new Exception("Service Login not specified");
                        }

                        if (string.IsNullOrEmpty(servicePassword))
                        {
                            throw new Exception("Service Password not specified");
                        }

                        config.RunAs(serviceLogin, servicePassword);
                    }
                }

                config.AddCommandLineSwitch("squirrel", _ => { });
                config.AddCommandLineDefinition("firstrun", _ => Environment.Exit(0));
                config.AddCommandLineDefinition("obsolete", _ => Environment.Exit(0));
                config.AddCommandLineDefinition("updated", version => { config.UseHostBuilder((env, settings) => new UpdateHostBuilder(env, settings, version, withOverlapping)); });
                config.AddCommandLineDefinition("install", version => { config.UseHostBuilder((env, settings) => new InstallAndStartHostBuilder(env, settings, version)); });
                config.AddCommandLineDefinition("uninstall", _ => { config.UseHostBuilder((env, settings) => new StopAndUninstallHostBuilder(env, settings)); });
            } catch (Exception ex)
            {
                Log.Error("Exception : ", ex);
            }
        }
예제 #19
0
 public void ApplyTo(HostConfigurator configurator)
 {
     configurator.RunAsLocalSystem();
 }