예제 #1
0
        void SetRecoveryOptions(ServiceDescription description)
        {
            _log.DebugFormat("Setting service recovery options for {0}", description.GetServiceName());

            try
            {
                WindowsServiceControlManager.SetServiceRecoveryOptions(description.GetServiceName(), _options);
            }
            catch (Exception ex)
            {
                _log.Error("Failed to set service recovery options", ex);
            }
        }
예제 #2
0
 public void CheckToSeeIfServiceRunning(ServiceDescription description)
 {
     if (ServiceController.GetServices().Where(s => s.ServiceName == description.GetServiceName()).Any())
     {
         _log.WarnFormat("There is an instance of this {0} running as a windows service", description);
     }
 }
예제 #3
0
        ServiceInstaller ConfigureServiceInstaller()
        {
            var installer = new ServiceInstaller
            {
                ServiceName        = _description.GetServiceName(),
                Description        = _description.Description,
                DisplayName        = _description.DisplayName,
                ServicesDependedOn = _dependencies.ToArray(),
                StartType          = _startMode,
            };

            CustomizeInstaller(installer);

            return(installer);
        }
예제 #4
0
        public void Start()
        {
            _input    = new ChannelAdapter();
            ServerUri = new UriBuilder("http", "localhost", _port, "Topshelf/" + _description.GetServiceName()).Uri;
            _log.InfoFormat("Loading dashboard at Uri: {0}", ServerUri);
            _server = new HttpServer(ServerUri, new PoolFiber(), _input, new PatternMatchConnectionHandler[]
            {
                new VersionConnectionHandler(),
                new StaticResourceHandler(@"\.png$", "Topshelf.Dashboard.images.", "image/png", "GET"),
                new StaticResourceHandler(@"\.css$", "Topshelf.Dashboard.styles.", "text/css", "GET"),
                new DashboardConnectionHandler(_serviceCoordinator)
            });

            _server.Start();
        }
예제 #5
0
        public void Run()
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            _log.Info("Starting up as a winservice application");

            if (!WindowsServiceControlManager.IsInstalled(_description.GetServiceName()))
            {
                string message =
                    string.Format("The {0} service has not been installed yet. Please run '{1} install'.",
                                  _description, Assembly.GetEntryAssembly().GetName());
                _log.Fatal(message);
                throw new ConfigurationException(message);
            }

            _log.Debug("[Topshelf] Starting up as a windows service application");

            Run(this);
        }
예제 #6
0
        public override void Install(IDictionary stateSaver)
        {
            Installers.AddRange(_installers);

            if (_log.IsInfoEnabled)
            {
                _log.InfoFormat("Installing {0} service", _description.DisplayName);
            }

            base.Install(stateSaver);

            if (_log.IsDebugEnabled)
            {
                _log.Debug("Opening Registry");
            }

            using (RegistryKey system = Registry.LocalMachine.OpenSubKey("System"))
                using (RegistryKey currentControlSet = system.OpenSubKey("CurrentControlSet"))
                    using (RegistryKey services = currentControlSet.OpenSubKey("Services"))
                        using (RegistryKey service = services.OpenSubKey(_description.GetServiceName(), true))
                        {
                            service.SetValue("Description", _description.Description);

                            var imagePath = (string)service.GetValue("ImagePath");

                            _log.DebugFormat("Service path: {0}", imagePath);

                            imagePath += _arguments;

                            _log.DebugFormat("Image path: {0}", imagePath);

                            service.SetValue("ImagePath", imagePath);
                        }

            if (_log.IsDebugEnabled)
            {
                _log.Debug("Closing Registry");
            }
        }
예제 #7
0
 public void CheckToSeeIfServiceRunning(ServiceDescription description)
 {
     if (ServiceController.GetServices().Where(s => s.ServiceName == description.GetServiceName()).Any())
         _log.WarnFormat("There is an instance of this {0} running as a windows service", description);
 }
예제 #8
0
        void SetRecoveryOptions(ServiceDescription description)
        {
            _log.DebugFormat("Setting service recovery options for {0}", description.GetServiceName());

            try
            {
                WindowsServiceControlManager.SetServiceRecoveryOptions(description.GetServiceName(), _options);
            }
            catch (Exception ex)
            {
                _log.Error("Failed to set service recovery options", ex);
            }
        }