Exemplo n.º 1
0
        static void Main(string[] args)
        {
            AgentRuntime.Bootstrap(typeof(Program).Assembly);

            HostFactory.New(x =>
            {
                x.UseSerilog();
                x.Service <AgentService>(sc =>
                {
                    sc.ConstructUsing(AgentRuntime.Resolve <AgentService>);
                    sc.WhenStarted(s => s.Start());
                    sc.WhenStopped(s => s.Stop());
                    sc.WhenShutdown(s => s.Dispose());
                });

                //More options exists. Like instance name, which you could supply using
                //command line and then host more instances of the same service. NOTE! Don't
                //forget that you would have to configure a different host for the second server.
                x.SetServiceName("Digger.Agent");
                x.SetDescription("Digger Agent service for collecting measurement data.");

                //Here you can take advantage of specifying specific user-accounts, service accounts etc
                //used to run the service and thereby limit access to resources like file-system,
                //databases etc.
                x.RunAsLocalSystem();
                x.StartAutomatically();
                x.EnableShutdown();
            }).Run();
        }
Exemplo n.º 2
0
 public void An_empty_command_line()
 {
     _host = HostFactory.New(x =>
     {
         x.ApplyCommandLine("");
     });
 }
Exemplo n.º 3
0
 public void Service_install_command_line()
 {
     _host = HostFactory.New(x =>
     {
         x.ApplyCommandLine("install");
     });
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            string srvName = System.Configuration.ConfigurationManager.AppSettings["srvname"];

            if (string.IsNullOrEmpty(srvName))
            {
                srvName = "JackTime2Run";
            }
            string srvDesc = System.Configuration.ConfigurationManager.AppSettings["srvdesc"];

            if (string.IsNullOrEmpty(srvDesc))
            {
                srvDesc = "JackTime2Run的定时服务,使用Quartz.net,可定时调用.dll|.exe(c#代码)|.cs文件";
            }
            var host = HostFactory.New(configuration =>
            {
                configuration.Service <Host>(callback =>
                {
                    callback.ConstructUsing(s => new Host(srvName, srvDesc));
                    callback.WhenStarted(service => service.Start());
                    callback.WhenStopped(service => service.Stop());
                });
                configuration.SetDisplayName(srvName);
                configuration.SetServiceName(srvName);
                configuration.SetDescription(srvDesc);
                configuration.RunAsLocalSystem();
            });

            host.Run();
        }
        static void Main(string[] args)
        {
            ILog log = LogManager.GetLogger("FileLogger");

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            const string name        = "ControlWorksPrintService";
            const string description = "Control Works print service";

            log.Info($"Initializing Service {name} - {description}");

            try
            {
                var host = HostFactory.New(configuration =>
                {
                    configuration.Service <Host>(callback =>
                    {
                        callback.ConstructUsing(s => new Host());
                        callback.WhenStarted(service => service.Start());
                        callback.WhenStopped(service => service.Stop());
                    });
                    configuration.SetDisplayName(name);
                    configuration.SetServiceName(name);
                    configuration.SetDescription(description);
                    configuration.RunAsLocalSystem();
                });
                host.Run();
            }
            catch (Exception ex)
            {
                log.Error("ControlWorksFaspacService Service fatal exception.");
                log.Error(ex.Message, ex);
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            HostFactory.New(x =>
            {
                x.Service <Monitor>(s =>
                {
                    s.ConstructUsing(_ => new Monitor());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });

                x.UseNLog();
                x.RunAsNetworkService();
                x.StartAutomatically();

                x.SetDescription("Monitor działania baterii");
                x.SetDisplayName("Batery Monitor");
                x.SetServiceName("Batery_Monitor");

                x.EnableServiceRecovery(r =>
                {
                    r.RestartService(1);
                    r.RestartService(2);
                    r.RestartService(3);
                    r.SetResetPeriod(1);
                });
            })
            .Run();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var host = HostFactory.New(configure =>
            {
                configure.HostService(ConfigureAppConfiguration, ConfigureServices, ConfigureLogging);

                configure.SetDisplayName("EMG WcfService");

                configure.SetServiceName("EMG.WcfService");

                configure.SetDescription("A Windows service created by EMG");

                configure.EnableServiceRecovery(rc => rc.RestartService(TimeSpan.FromMinutes(1))
                                                .RestartService(TimeSpan.FromMinutes(5))
                                                .RestartService(TimeSpan.FromMinutes(10))
                                                .SetResetPeriod(1));

                configure.RunAsLocalService();

                configure.StartAutomaticallyDelayed();

                configure.SetStopTimeout(TimeSpan.FromMinutes(5));
            });

            host.Run();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            NLogLogger.Use();
            Logger.Configure(x => x.UseNLogLogger());

            WindsorContainer container = new WindsorContainer();

            container.AddFacility <LoggingFacility>(f => f.LogUsing(LoggerImplementation.NLog));
            container.Install(FromAssembly.This());
            container.Register(Component.For <Server>().LifestyleSingleton());

            Host host = HostFactory.New(conf =>
            {
                conf.Service <Server>(s =>
                {
                    s.ConstructUsing(name => {
                        return(container.Resolve <Server>());
                    });
                    s.WhenStarted(program => program.Start());
                    s.WhenStopped(program => program.Stop());
                });
                conf.RunAsLocalSystem();

                conf.SetServiceName("PluginFramework-Server");
                conf.SetDescription("Server for the plugin framework");
                conf.SetDisplayName("PluginFramework-Server");
                conf.UseNLog();
            });

            host.Run();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            var app = new App();

            var host = HostFactory.New(config =>
            {
                config.EnableServiceRecovery(r =>
                {
                    r.OnCrashOnly();
                    r.SetResetPeriod(1);
                    r.RestartService(1);
                });
                config.UseSimpleInjector(app.GetContainer());
                config.Service <IMainWorker>(s =>
                {
                    s.ConstructUsingSimpleInjector();
                    s.WhenStarted(service => service.Start());
                    s.WhenStopped(service => service.Stop());
                });
                config.RunAsLocalSystem();

                config.SetDescription("MPE.SS - Server Surveillance");
                config.SetDisplayName("MPE.SS");
                config.SetServiceName("MPE.SS");
            });

            host.Run();
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            var host = HostFactory.New(x =>
            {
                x.SetServiceName(ServiceName);

                x.Service <Updater>(s =>
                {
                    s.ConstructUsing(name => new Updater());

                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });

                x.RunAsLocalSystem();

                x.SetDisplayName(ServiceName);
                x.SetDescription(ServiceName);
                x.SetServiceName(ServiceName);
            });

            host.Run();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            var host = HostFactory.New(x =>
            {
                x.Service <WindowsService>(s =>
                {
                    s.ConstructUsing(name => {
                        var configuration = JsonConvert.DeserializeObject <Configuration>(System.IO.File.ReadAllText("config.json"));
                        return(new WindowsService(configuration));
                    });
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });

                x.RunAsLocalSystem();

                x.SetDescription("This as a test service");
                x.SetDisplayName("TestService #1");
                x.SetServiceName("TestService1");
            });

            var rc = host.Run();

            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());

            Environment.ExitCode = exitCode;
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure();

            using (var container = new WindsorContainer())
            {
                container.Register(Classes.FromAssemblyInThisApplication()
                                   .Where(a => true)
                                   .LifestyleSingleton()
                                   .WithServiceDefaultInterfaces());

                var host = HostFactory.New(x =>
                {
                    x.Service <EmptyKingdomService>(s =>
                    {
                        s.ConstructUsing(n => new EmptyKingdomService(container));
                        s.WhenStarted(tc => tc.Start());
                        s.WhenStopped(tc => tc.Stop());
                    });
                    x.RunAsLocalService();

                    x.SetDescription("EmptyKingdom");
                    x.SetDisplayName("EmptyKingdom vkontakte wall updater");
                });
                var ec       = host.Run();
                var exitCode = (int)Convert.ChangeType(ec, ec.GetTypeCode());
                Environment.ExitCode = exitCode;
            }
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            var host = HostFactory.New(x =>
            {
                x.SetServiceName(ServiceName);

                x.Service <IAsimovDeployService>(s =>
                {
                    s.ConstructUsing(name => new AsimovDeployService());

                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });

                x.RunAsLocalSystem();
                x.SetDisplayName(ServiceName);
                x.SetDescription(ServiceName);
                x.SetServiceName(ServiceName);
            });

            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;

            host.Run();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Configures a service.
        /// </summary>
        /// <param name="container">An Autofac container.</param>
        /// <returns>
        /// Returns a host instance.
        /// </returns>
        private static Host ConfigureHost(IContainer container)
        {
            var settings = container.Resolve <ISeekerSettings>();

            var host = HostFactory.New(x =>
            {
                x.EnableShutdown();
                x.RunAsLocalSystem();
                x.SetServiceName("Seeker");
                x.SetDisplayName("Seeker");
                x.SetDescription("Collects log messages");
                x.StartAutomatically();

                x.Service <SeekerService>(cfg =>
                {
                    cfg.ConstructUsing(() => container.Resolve <SeekerService>());
                    cfg.WhenStarted <SeekerService>(srv => srv.Start());
                    cfg.WhenStopped <SeekerService>(srv => srv.Stop());

                    cfg.WithNancyEndpoint(x, c =>
                    {
                        c.AddHost(port: settings.Port);
                        c.CreateUrlReservationsOnInstall();
                        c.Bootstrapper = new SeekerBootstrapper(AutofacContext.Container);
                    });
                });
                x.EnableServiceRecovery(cfg => cfg.RestartService(1));
                x.UseNLog();
                x.OnException(ex => HostLogger.Get("Seeker")
                              .Error("Unhandled exception.", ex));
            });

            return(host);
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            var host = HostFactory.New(x =>
            {
                x.UseLinuxIfAvailable();
                x.Service <StratosSelfHost>(s =>
                {
                    s.ConstructUsing(settings => new StratosSelfHost($"http://+:{Port}{ApiEndpoint}"));
                    s.WhenStarted(service => service.Start());
                    s.WhenStopped(service => service.Stop());
                    s.WithNancyEndpoint(x, c =>
                    {
                        c.AddHost(port: Port);
                        c.CreateUrlReservationsOnInstall();
                        c.OpenFirewallPortsOnInstall(firewallRuleName: "StratosService");
                    });
                });

                x.StartAutomatically();
                x.SetServiceName("StratosService");
                x.SetDisplayName("StratosService");
                x.SetDescription("StratosService");
                x.RunAsLocalSystem();
            });

            host.Run();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Main.
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            var cfg = HostFactory.New(x => {
                x.Service <QuartzServer>(configurator => {
                    configurator.ConstructUsing(builder => new QuartzServer());
                    configurator.WhenStarted(server => {
                        var modulePath                = ConfigurationManager.AppSettings["xafApplicationPath"];
                        var connectionString          = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                        XafApplication xafApplication = XafApplicationFactory.GetApplication(modulePath, connectionString);
                        server.Initialize(xafApplication);
                        server.Start();
                    });
                    configurator.WhenPaused(server => server.Pause());
                    configurator.WhenContinued(server => server.Resume());
                    configurator.WhenStopped(server => server.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription(Configuration.ServiceDescription);
                x.SetDisplayName(Configuration.ServiceDisplayName);
                x.SetServiceName(Configuration.ServiceName);

                x.RunAsLocalService();
                x.StartAutomaticallyDelayed();
            });


            cfg.Run();
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            XmlConfigurator.ConfigureAndWatch(
                new FileInfo(".\\log4net.config"));

            var host = HostFactory.New(x =>
            {
                x.EnableDashboard();
                x.Service <WHSScanProvider>(s =>
                {
                    s.SetServiceName("WHSScanProvider");
                    s.ConstructUsing(name => new WHSScanProvider());
                    s.WhenStarted(tc =>
                    {
                        XmlConfigurator.ConfigureAndWatch(
                            new FileInfo(".\\log4net.config"));
                        tc.Start();
                    });
                    s.WhenStopped(tc => tc.Stop());
                });

                x.RunAsLocalSystem();
                x.SetDescription("WHSScanProvider Description");
                x.SetDisplayName("WHSScanProvider");
                x.SetServiceName("WHSScanProvider");
            });

            host.Run();
        }
        public void Run()
        {
            var topShelfHost = HostFactory.New(host =>
            {
                host.UseAutofacContainer(IocContainer);
                host.Service <GenericService>(s =>
                {
                    s.ConstructUsingAutofacContainer();
                    s.WhenStarted((svc, hostControl) => svc.Start(hostControl));
                    s.WhenStopped((svc, hostControl) => svc.Stop(hostControl));
                });

                // Service start mode.
                host.StartAutomaticallyDelayed();
                //host.StartAutomatically();
                //host.StartManually();

                // Service descriptors.
                host.SetDescription(Configuration.GetSection("Defaults")["Description"]);
                host.SetDisplayName(Configuration.GetSection("Defaults")["DisplayName"]);
                host.SetServiceName(Configuration.GetSection("Defaults")["ServiceName"]);

                // Service user.
                host.RunAsLocalSystem();
                //host.RunAsLocalService();
                //host.RunAsNetworkService();
                //host.RunAsPrompt();
            });

            topShelfHost.Run();
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            var host = HostFactory.New(x =>
            {
                //x.UseNLog();
                x.Service <SampleService>(s =>
                {
                    s.ConstructUsing(settings => new SampleService());
                    s.WhenStarted(service => service.Start());
                    s.WhenStopped(service => service.Stop());
                    s.WithNancyEndpoint(x, c =>
                    {
                        c.AddHost(port: 3333);
                        c.CreateUrlReservationsOnInstall();
                        c.OpenFirewallPortsOnInstall(firewallRuleName: "AiXin.Service");
                    });
                });

                x.StartAutomatically();
                x.SetServiceName("AiXin.Service");
                x.SetDisplayName("AiXin.Service");
                x.SetDescription("AiXin Windows Service");
                x.RunAsLocalSystem();
            });

            host.Run();
        }
Exemplo n.º 20
0
        public static int Main(string[] args)
        {
            ITraceManager traceManager = new Log4netTraceManager(new Log4netWrapper());

            var rc = HostFactory.New(x =>
            {
                x.Service <ApiService>(sc =>
                {
                    sc.ConstructUsing(s => new ApiService());
                    sc.WhenStarted((s, hostControl) => s.Start(hostControl));
                    sc.WhenStopped((s, hostControl) => s.Stop(hostControl));
                });

                x.RunAsLocalSystem();
                x.SetDescription(ApiService.Description);
                x.SetDisplayName(ApiService.DisplayName);
                x.SetServiceName(ApiService.ServiceName);

                x.EnableServiceRecovery(recoveryOption => recoveryOption.RestartService(0));
                x.StartAutomaticallyDelayed();
            });

            TopshelfExitCode exitCode = TopshelfExitCode.AbnormalExit;

            try
            {
                exitCode = rc.Run();
            }
            catch (Exception e)
            {
                traceManager.TraceError(e, "ERROR on service starting.");
            }
            return((int)exitCode);
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo(".\\log4net.config"));

            var h = HostFactory.New(x =>
            {
                x.AfterStoppingServices(n => Console.WriteLine("AfterStoppingServices action invoked, services are stopping"));

                x.EnableDashboard();

                x.Service <TownCrier>(s =>
                {
                    s.SetServiceName("TownCrier");
                    s.ConstructUsing(name => new TownCrier());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });

                x.RunAsLocalSystem();

                x.SetDescription("Sample Topshelf Host");
                x.SetDisplayName("Stuff");
                x.SetServiceName("stuff");
            });

            h.Run();
        }
Exemplo n.º 22
0
        //service installer/stop/start/uninstaller
        private static void service()
        {
            HostFactory.New(x => {
                x.Service <FiredumpService>((ServiceConfigurator <FiredumpService> s) =>
                {
                    s.ConstructUsing(settings =>
                    {
                        var serviceName = settings.ServiceName;
                        return(new FiredumpService());
                    });
                    s.WhenStarted((ms, hostControl) => ms.Start(hostControl));
                    s.WhenStopped((ms, hostControl) => ms.Stop(hostControl));
                });

                x.EnablePauseAndContinue();
                x.EnableShutdown();
                x.StartManually();
                x.RunAsLocalSystem();
                //kathe fora pou allazei afto ama den egine to palio service uninstall meni sta windows
                x.SetServiceName(Consts.SERVICE_NAME);

                x.UseNLog();

                //topshelf supper BUG in setting displayName
                //tha kanei set to service name kai tha ftiaksei dio diaforetika services sta windows service registry!
                //x.SetDisplayName(Consts.SERVICE_DESC);
            }).Run();
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            var host = HostFactory.New(configure =>
            {
                configure.UseStartup <NybusStartup>();

                configure.SetDisplayName("Nybus Windows Service");

                configure.SetServiceName("NybusWindowsService");

                configure.SetDescription("A Windows service running Nybus");

                configure.EnableServiceRecovery(rc => rc.RestartService(TimeSpan.FromMinutes(1))
                                                .RestartService(TimeSpan.FromMinutes(5))
                                                .RestartService(TimeSpan.FromMinutes(10))
                                                .SetResetPeriod(1));

                configure.RunAsLocalService();

                configure.StartAutomaticallyDelayed();

                configure.SetStopTimeout(TimeSpan.FromMinutes(5));
            });

            host.Run();
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            var host = HostFactory.New(x =>
            {
                // Service description
                x.SetServiceName("ConsulNotifierService");
                x.SetDisplayName("Consul Notifier Service");
                x.SetDescription("Notify Consul application about new sites in current machine.");

                // Service settings
                x.EnableShutdown();
                x.StartAutomatically();
                x.RunAsLocalSystem();

                // Service recovery options
                x.EnableServiceRecovery(r =>
                {
                    r.RestartService(0);
                    r.OnCrashOnly();
                });

                // Service contract, only one per service
                x.Service <WindowsServiceHost>(s =>
                {
                    s.ConstructUsing(() => new WindowsServiceHost());
                    s.WhenStarted((svc, control) => svc.Start(control));
                    s.WhenStopped((svc, control) => svc.Stop(control));
                    s.WhenPaused((svc, control) => svc.Stop(control));
                    s.WhenContinued((svc, control) => svc.Start(control));
                });
            });

            host.Run();
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            try
            {
                const string name        = ".Windows10SpotlightBackgrounds";
                const string description = "Windows 10 Spotlight Backgrounds";

                var host = HostFactory.New(configuration =>
                {
                    configuration.Service <Host>(s =>
                    {
                        s.ConstructUsing(atlasHost => new Host());
                        s.WhenStarted(i => i.Start());
                        s.WhenStopped(i => i.Stop());
                    });
                    configuration.SetDescription(name);
                    configuration.SetServiceName(name);
                    configuration.SetDescription(description);
                    configuration.RunAsLocalSystem();
                });

                host.Run();
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            CodeService.Container = new WindsorContainer();
            CodeService.Container.Install(FromAssembly.This());

            var codeServices         = CodeService.Container.Resolve <ICodeServices>();
            var presentationServices = CodeService.Container.Resolve <IGenericServices <Presentation> >();
            var webApp   = CodeService.Container.Resolve <IServiceable>();
            var provider = ConfigurationManager.AppSettings["contentProvider"];

            if (string.IsNullOrEmpty(provider))
            {
                provider = typeof(FileSystemContentProvider).ToString();
            }
            var contentProvider = (IContentProvider <Presentation>)Activator.CreateInstance(Type.GetType(provider));

            var hostObj = HostFactory.New(x =>
            {
                x.Service <CodeService>(s =>
                {
                    s.ConstructUsing(name => new CodeService(codeServices, presentationServices, webApp, contentProvider));
                    s.WhenStarted((ls, host) => ls.Start(host));
                    s.WhenStopped((ls, host) => ls.Stop(host));
                });

                x.RunAsLocalSystem().SetDescription("Code services console");
                x.SetDisplayName("Code Service");
                x.SetServiceName("CodeService");
                x.StartAutomatically();
            });

            hostObj.Run();
        }
Exemplo n.º 27
0
 public void Dash_something_or_other_command_line()
 {
     _host = HostFactory.New(x =>
     {
         x.ApplyCommandLine("-unknownArgument");
     });
 }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            var service = HostFactory.New(x =>
            {
                x.Service <DirPrintWatcher>(s =>
                {
                    s.ConstructUsing(name => new DirPrintWatcher());
                    s.WhenStarted(dpw => dpw.Start());
                    s.WhenStopped(dpw => dpw.Stop());
                });

                x.SetDescription("Watches configured directory for new files and prints them.");
                x.SetDisplayName("Directory Print Watcher");
                x.SetServiceName("DirPrintWatcher");

                x.StartAutomatically();
                x.EnableServiceRecovery(r =>
                {
                    r.RestartService(0);
                });

                x.DependsOn("Spooler");
            });

            var runner = service.Run();

            var exitCode = (int)Convert.ChangeType(runner, runner.GetTypeCode());

            Environment.ExitCode = exitCode;
        }
Exemplo n.º 29
0
        static void Main()
        {
            var host = HostFactory.New(x =>
            {
                x.UseNLog();

                x.Service <SampleService>(s =>
                {
                    s.ConstructUsing(settings => new SampleService());
                    s.WhenStarted(service => service.Start());
                    s.WhenStopped(service => service.Stop());
                    s.WithNancyEndpoint(x, c =>
                    {
                        c.AddHost(port: 20005);
                        c.AddHost(port: 20006);
                        c.CreateUrlReservationsOnInstall();
                        c.OpenFirewallPortsOnInstall(firewallRuleName: "topshelf.nancy.sampleservice");
                    });
                });
                x.StartAutomatically();
                x.SetServiceName("topshelf.nancy.sampleservice");
                x.SetDisplayName("Topshelf.Nancy.SampleService");
                x.SetDescription("Sample Service for the Topshelf.Nancy project");
                x.RunAsNetworkService();
            });

            host.Run();
        }
Exemplo n.º 30
0
        private static void Main(string[] args)
        {
            var serviceName        = ConfigurationManager.AppSettings["ServiceName"];
            var cronExpression     = ConfigurationManager.AppSettings["CronExpression"];
            var powershellFileName = ConfigurationManager.AppSettings["PowerShellFileName"];
            var host = HostFactory.New(x =>
            {
                x.Service <HostService>(s =>
                {
                    s.ConstructUsing(name =>
                    {
                        return(new HostService(powershellFileName, cronExpression));
                    });
                    s.WhenStarted(tc => { tc.Start(); });
                    s.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();
                x.StartAutomatically();
                x.DependsOnMsmq();
                x.SetDescription(serviceName);
                x.SetDisplayName(serviceName);
                x.SetServiceName(serviceName);
                x.ConfigureTimeout();
            });

            host.Run();
        }