├── Topshelf.snk
├── src
├── Topshelf
│ ├── packages.config
│ ├── Caching
│ │ ├── KeySelector.cs
│ │ ├── MissingValueProvider.cs
│ │ └── CacheItemCallback.cs
│ ├── Logging
│ │ ├── TypeExtensions.cs
│ │ ├── HostLoggerConfigurator.cs
│ │ ├── LogWriterFactory.cs
│ │ ├── LogWriterOutputProvider.cs
│ │ ├── TraceHostLoggerConfigurator.cs
│ │ └── TopshelfConsoleTraceListener.cs
│ ├── HostStopContext.cs
│ ├── HostStartedContext.cs
│ ├── HostStoppedContext.cs
│ ├── Configuration
│ │ ├── CommandLineParser
│ │ │ ├── ICommandLineElement.cs
│ │ │ ├── ITokenElement.cs
│ │ │ ├── IArgumentElement.cs
│ │ │ ├── ISwitchElement.cs
│ │ │ ├── IDefinitionElement.cs
│ │ │ ├── Parser.cs
│ │ │ ├── Result.cs
│ │ │ ├── AbstractParser.cs
│ │ │ ├── ArgumentElement.cs
│ │ │ └── TokenElement.cs
│ │ ├── Builders
│ │ │ ├── EnvironmentBuilder.cs
│ │ │ ├── ServiceBuilder.cs
│ │ │ ├── HostBuilder.cs
│ │ │ ├── StopBuilder.cs
│ │ │ └── CommandBuilder.cs
│ │ ├── Options
│ │ │ ├── Option.cs
│ │ │ ├── LocalSystemOption.cs
│ │ │ ├── InteractiveOption.cs
│ │ │ ├── DisabledOption.cs
│ │ │ ├── ManualStartOption.cs
│ │ │ ├── AutostartOption.cs
│ │ │ ├── DelayedOption.cs
│ │ │ ├── LocalServiceOption.cs
│ │ │ ├── NetworkServiceOption.cs
│ │ │ ├── SystemOnlyHelpOption.cs
│ │ │ ├── DisplayNameOption.cs
│ │ │ ├── SudoOption.cs
│ │ │ ├── ServiceNameOption.cs
│ │ │ ├── UnknownOption.cs
│ │ │ ├── RunOption.cs
│ │ │ ├── ServiceDescriptionOption.cs
│ │ │ ├── HelpOption.cs
│ │ │ ├── StartOption.cs
│ │ │ ├── StopOption.cs
│ │ │ ├── InstallOption.cs
│ │ │ ├── UninstallOption.cs
│ │ │ ├── ServiceAccountOption.cs
│ │ │ ├── InstanceOption.cs
│ │ │ └── CommandOption.cs
│ │ ├── HostConfigurators
│ │ │ ├── EnvironmentBuilderFactory.cs
│ │ │ ├── ServiceBuilderFactory.cs
│ │ │ ├── HostBuilderFactory.cs
│ │ │ ├── CommandLineConfigurator.cs
│ │ │ ├── HostBuilderConfigurator.cs
│ │ │ ├── StartConfigurator.cs
│ │ │ ├── SystemOnlyHelpHostConfigurator.cs
│ │ │ ├── SudoConfigurator.cs
│ │ │ ├── UnknownCommandLineOptionHostConfigurator.cs
│ │ │ ├── CommandConfigurator.cs
│ │ │ ├── RunAsVirtualAccountHostConfigurator.cs
│ │ │ ├── RunAsServiceAccountHostConfigurator.cs
│ │ │ ├── RunHostConfiguratorAction.cs
│ │ │ ├── UninstallHostConfiguratorAction.cs
│ │ │ ├── StartModeHostConfigurator.cs
│ │ │ ├── DependencyHostConfigurator.cs
│ │ │ ├── InstallHostConfiguratorAction.cs
│ │ │ ├── CommandLineSwitchConfigurator.cs
│ │ │ ├── CommandLineDefinitionConfigurator.cs
│ │ │ └── RunAsUserHostConfigurator.cs
│ │ ├── Configurators
│ │ │ ├── Configurator.cs
│ │ │ ├── ValidationResultDisposition.cs
│ │ │ ├── ConfigurationResult.cs
│ │ │ └── ValidateResult.cs
│ │ ├── Credentials.cs
│ │ ├── TestHostExtensions.cs
│ │ ├── ServiceRecoveryConfiguratorExtensions.cs
│ │ ├── ServiceConfigurators
│ │ │ ├── ControlServiceConfigurator.cs
│ │ │ └── ServiceConfiguratorBase.cs
│ │ ├── UninstallHostConfiguratorExtensions.cs
│ │ └── Constants
│ │ │ └── KnownServiceNames.cs
│ ├── Runtime
│ │ ├── ServiceFactory.cs
│ │ ├── Windows
│ │ │ ├── SafeTokenHandle.cs
│ │ │ ├── WindowsUserAccessControl.cs
│ │ │ ├── SCMHandle.cs
│ │ │ ├── ServiceRecoveryAction.cs
│ │ │ ├── WindowsHostEnvironmentBuilder.cs
│ │ │ ├── RestartServiceRecoveryAction.cs
│ │ │ ├── RunProgramRecoveryAction.cs
│ │ │ ├── RestartSystemRecoveryAction.cs
│ │ │ ├── ServiceRecoveryOptions.cs
│ │ │ └── Kernel32.cs
│ │ ├── HostStartMode.cs
│ │ ├── InstallHostSettings.cs
│ │ ├── ServiceEvents.cs
│ │ └── EventCallbackList.cs
│ ├── PowerEventArguments.cs
│ ├── ServiceControl.cs
│ ├── SessionChangedArguments.cs
│ ├── HostStartContext.cs
│ ├── ServiceCustomCommand.cs
│ ├── ServicePowerEvent.cs
│ ├── ServiceSuspend.cs
│ ├── ServiceSessionChange.cs
│ ├── Host.cs
│ ├── SessionChangeReasonCode.cs
│ ├── TopshelfExitCode.cs
│ ├── ServiceShutdown.cs
│ ├── HostControl.cs
│ ├── Exceptions
│ │ ├── TopshelfException.cs
│ │ ├── ServiceBuilderException.cs
│ │ ├── HostConfigurationException.cs
│ │ └── ServiceControlException.cs
│ └── Hosts
│ │ └── HelpHost.cs
├── Topshelf.Log4Net
│ ├── app.config
│ └── packages.config
├── .nuget
│ ├── packages.config
│ └── NuGet.Config
├── Topshelf.NLog
│ ├── packages.config
│ └── NLogConfiguratorExtensions.cs
├── Topshelf.Serilog
│ ├── packages.config
│ ├── Logging
│ │ └── SerilogLogWriterFactory.cs
│ └── SerilogConfigurationExtensions.cs
├── SampleTopshelfService
│ ├── packages.config
│ ├── app.config
│ ├── SampleSansInterfaceService.cs
│ └── log4net.config
├── Topshelf.Elmah
│ ├── packages.config
│ ├── ElmahConfigurationExtensions.cs
│ └── Logging
│ │ └── ElmahLogWriterFactory.cs
├── SampleTopshelfRehabService
│ ├── packages.config
│ ├── app.config
│ ├── log4net.config
│ └── Program.cs
├── SampleTopshelfSuperviseService
│ ├── packages.config
│ ├── app.config
│ ├── Program.cs
│ ├── log4net.config
│ └── PoorlyBehavedService.cs
├── Topshelf.Tests
│ ├── packages.config
│ └── BeforeStart_Specs.cs
├── Topshelf.Supervise
│ ├── Scripting
│ │ ├── CommandScriptStepResult.cs
│ │ ├── CommandScriptStepArguments.cs
│ │ ├── Command.cs
│ │ ├── CommandScriptStepAudit.cs
│ │ └── CommandScriptStep.cs
│ ├── Threading
│ │ ├── ScheduledOperationExecuter.cs
│ │ ├── OperationExecutor.cs
│ │ ├── ScheduledOperation.cs
│ │ ├── ScheduledOperationExecuterImpl.cs
│ │ ├── Fiber.cs
│ │ └── FiberExtensions.cs
│ ├── ServiceAvailabilityHost.cs
│ ├── ServiceAvailability.cs
│ ├── RestartServiceExtensions.cs
│ ├── SuperviseConfigurator.cs
│ ├── HostControlProxy.cs
│ ├── SuperviseServiceConfigurator.cs
│ └── SuperviseConfiguratorExtensions.cs
├── Topshelf.Rehab
│ ├── AppDomainHostControl.cs
│ └── RehabServiceBuilder.cs
└── SolutionVersion.cs
├── .gitattributes
├── doc
└── source
│ ├── troubleshooting
│ └── index.rst
│ ├── configuration
│ ├── index.rst
│ └── logging.rst
│ ├── installation
│ ├── index.rst
│ ├── bugs.rst
│ ├── prerequisites.rst
│ └── install.rst
│ ├── overview
│ └── index.rst
│ └── index.rst
├── CHANGELOG.md
├── .gitignore
└── template.nuspec
/Topshelf.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arch/Topshelf/develop/Topshelf.snk
--------------------------------------------------------------------------------
/src/Topshelf/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Set default behaviour, in case users don't have core.autocrlf set.
2 | * text=false
3 |
--------------------------------------------------------------------------------
/doc/source/troubleshooting/index.rst:
--------------------------------------------------------------------------------
1 | Troubleshooting Topshelf
2 | ========================
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/Topshelf.Log4Net/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/Topshelf/Caching/KeySelector.cs:
--------------------------------------------------------------------------------
1 | namespace Topshelf.Caching
2 | {
3 | delegate TKey KeySelector(TValue value);
4 | }
--------------------------------------------------------------------------------
/src/.nuget/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/Topshelf/Caching/MissingValueProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Topshelf.Caching
2 | {
3 | delegate TValue MissingValueProvider(TKey key);
4 | }
--------------------------------------------------------------------------------
/src/Topshelf/Caching/CacheItemCallback.cs:
--------------------------------------------------------------------------------
1 | namespace Topshelf.Caching
2 | {
3 | delegate void CacheItemCallback(TKey key, TValue value);
4 | }
--------------------------------------------------------------------------------
/src/Topshelf.NLog/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/Topshelf.Log4Net/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/Topshelf.Serilog/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/SampleTopshelfService/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/Topshelf.Elmah/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/SampleTopshelfRehabService/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/SampleTopshelfSuperviseService/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/SampleTopshelfRehabService/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/SampleTopshelfService/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/SampleTopshelfSuperviseService/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Topshelf v4.0
2 |
3 | * Removed support for .NET < 4.5.2
4 | * Moved build to FAKE
5 | * Using AppVeyor for public builds https://ci.appveyor.com/project/phatboyg/topshelf
6 | * Allow service users to have blank passwords (topshelf#285) via @ianbattersby
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build_output/*
2 | build_artifacts/*
3 | doc/build/*
4 |
5 | nuget.exe
6 |
7 | *.suo
8 | *.user
9 | packages
10 | *.dotCover
11 | *.dotSettings
12 |
13 | .fake
14 |
15 | bin
16 | obj
17 | _ReSharper*
18 |
19 | *.ReSharper
20 | *.cache
21 | *~
22 | *.swp
23 | *.bak
24 | *.orig
25 |
26 | # osx noise
27 | .DS_Store
28 | Gemfile.lock
29 |
--------------------------------------------------------------------------------
/doc/source/configuration/index.rst:
--------------------------------------------------------------------------------
1 | Configuring Topshelf
2 | """"""""""""""""""""
3 |
4 | Once Topshelf has been added to your service, you can configure the service using the Topshelf configuration API. Topshelf uses an internal domain specific language (DSL) for configuration, along with a series of fluent builders.
5 |
6 | .. toctree::
7 |
8 | quickstart.rst
9 | config_api.rst
10 | logging.rst
11 |
--------------------------------------------------------------------------------
/src/Topshelf/Logging/TypeExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace Topshelf.Logging
2 | {
3 | using System;
4 |
5 | static class TypeExtensions
6 | {
7 | static readonly TypeNameFormatter _typeNameFormatter = new TypeNameFormatter();
8 |
9 |
10 | public static string GetTypeName(this Type type)
11 | {
12 | return _typeNameFormatter.GetTypeName(type);
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/doc/source/installation/index.rst:
--------------------------------------------------------------------------------
1 | Topshelf Installation
2 | =====================
3 |
4 | This section of the online docs will explain how to get Topshelf into
5 | your project. It will also show you where to get help, how to report bugs, etc.
6 | Hopefully, you will find it useful as you explore the Topshelf framework.
7 |
8 | .. toctree::
9 |
10 | prerequisites.rst
11 | install.rst
12 | help.rst
13 | bugs.rst
14 |
--------------------------------------------------------------------------------
/doc/source/installation/bugs.rst:
--------------------------------------------------------------------------------
1 | How to report bugs
2 | ==================
3 |
4 | If you run into a bug, please spend a minute collecting the right information
5 | to help us fix the bug.
6 |
7 | The most valuable piece of information you can give us, is always give us a
8 | failing unit test, if you can't give us that then how to reproduce the bug in a
9 | step by step fashion. Other wise its going to be a lot of back and forth until
10 | we can better understand and get to a failing unit test.
--------------------------------------------------------------------------------
/doc/source/installation/prerequisites.rst:
--------------------------------------------------------------------------------
1 | Prerequisites
2 | =============
3 |
4 | Topshelf is a .Net framework for C# and will need a .Net runtime to run on.
5 |
6 | To work with Topshelf you will need to be running on a Windows operating
7 | system. The developers of Topshelf regulary test on Windows 7 and
8 | Windows Server 2008RC2. Though it should still work on Windows Server 2003, as
9 | long as .Net 3.5 sp1 is installed.
10 |
11 | .Net Framework
12 | """"""""""""""
13 |
14 | Currently Topshelf is tested on .NET 3.5 Service Pack 1 and .NET 4.0.
15 |
--------------------------------------------------------------------------------
/doc/source/overview/index.rst:
--------------------------------------------------------------------------------
1 | Topshelf Overview
2 | =================
3 |
4 | Topshelf is a framework for hosting services written using the .NET framework. The creation of services is simplified, allowing developers to create a simple console application that can be installed as a service using Topshelf. The reason for this is simple: It is far easier to debug a console application than a service. And once the application is tested and ready for production, Topshelf makes it easy to install the application as a service.
5 |
6 | .. toctree::
7 |
8 | faq.rst
9 | commandline.rst
10 |
--------------------------------------------------------------------------------
/doc/source/index.rst:
--------------------------------------------------------------------------------
1 | .. Topshelf documentation master file, created by
2 | sphinx-quickstart on Mon Jan 17 15:29:48 2011.
3 | You can adapt this file completely to your liking, but it should at least
4 | contain the root `toctree` directive.
5 |
6 | Welcome to Topshelf's documentation!
7 | =======================================
8 |
9 | .. image:: http://topshelf-project.com/slide.1.png
10 |
11 | Contents:
12 |
13 | .. toctree::
14 | :maxdepth: 2
15 |
16 | installation/index.rst
17 | configuration/index.rst
18 | overview/index.rst
19 | troubleshooting/index.rst
20 |
21 |
22 | Indices and tables
23 | ==================
24 |
25 | * :ref:`genindex`
26 | * :ref:`modindex`
27 | * :ref:`search`
28 |
29 |
--------------------------------------------------------------------------------
/src/Topshelf.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/Topshelf/HostStopContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | public interface HostStopContext :
16 | HostControl
17 | {
18 | }
19 | }
--------------------------------------------------------------------------------
/src/Topshelf/HostStartedContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | public interface HostStartedContext :
16 | HostControl
17 | {
18 | }
19 | }
--------------------------------------------------------------------------------
/src/Topshelf/HostStoppedContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | public interface HostStoppedContext :
16 | HostControl
17 | {
18 | }
19 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/CommandLineParser/ICommandLineElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.CommandLineParser
14 | {
15 | interface ICommandLineElement
16 | {
17 | }
18 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/ServiceFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime
14 | {
15 | public delegate T ServiceFactory(HostSettings settings)
16 | where T : class;
17 | }
--------------------------------------------------------------------------------
/src/Topshelf/PowerEventArguments.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | public interface PowerEventArguments
16 | {
17 | PowerEventCode EventCode { get; }
18 | }
19 | }
--------------------------------------------------------------------------------
/src/Topshelf/Logging/HostLoggerConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Logging
14 | {
15 | public interface HostLoggerConfigurator
16 | {
17 | LogWriterFactory CreateLogWriterFactory();
18 | }
19 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Scripting/CommandScriptStepResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Scripting
14 | {
15 | public class CommandScriptStepResult :
16 | CommandScriptDictionary
17 | {
18 | }
19 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/Windows/SafeTokenHandle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Topshelf.Runtime.Windows
4 | {
5 | using System.Runtime.ConstrainedExecution;
6 | using System.Runtime.InteropServices;
7 | using System.Security;
8 | using Microsoft.Win32.SafeHandles;
9 |
10 | public sealed class SafeTokenHandle : SafeHandleZeroOrMinusOneIsInvalid
11 | {
12 | private SafeTokenHandle()
13 | : base(true) { }
14 |
15 | [DllImport("kernel32.dll")]
16 | [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
17 | [SuppressUnmanagedCodeSecurity]
18 | [return: MarshalAs(UnmanagedType.Bool)]
19 | private static extern bool CloseHandle(IntPtr handle);
20 |
21 | protected override bool ReleaseHandle()
22 | {
23 | return CloseHandle(handle);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Scripting/CommandScriptStepArguments.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Scripting
14 | {
15 | public class CommandScriptStepArguments :
16 | CommandScriptDictionary
17 | {
18 | }
19 | }
--------------------------------------------------------------------------------
/src/Topshelf/Logging/LogWriterFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Logging
14 | {
15 | public interface LogWriterFactory
16 | {
17 | LogWriter Get(string name);
18 |
19 | void Shutdown();
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Topshelf/ServiceControl.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | public interface ServiceControl
16 | {
17 | bool Start(HostControl hostControl);
18 | bool Stop(HostControl hostControl);
19 | }
20 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Builders/EnvironmentBuilder.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Builders
14 | {
15 | using Runtime;
16 |
17 | public interface EnvironmentBuilder
18 | {
19 | HostEnvironment Build();
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/CommandLineParser/ITokenElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.CommandLineParser
14 | {
15 | interface ITokenElement :
16 | ICommandLineElement
17 | {
18 | string Token { get; }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/Topshelf/SessionChangedArguments.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | public interface SessionChangedArguments
16 | {
17 | SessionChangeReasonCode ReasonCode { get; }
18 | int SessionId { get; }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/CommandLineParser/IArgumentElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.CommandLineParser
14 | {
15 | interface IArgumentElement :
16 | ICommandLineElement
17 | {
18 | string Id { get; }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/Option.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public interface Option
18 | {
19 | void ApplyTo(HostConfigurator configurator);
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Threading/ScheduledOperationExecuter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Threading
14 | {
15 | interface ScheduledOperationExecuter :
16 | ScheduledOperation
17 | {
18 | void Execute();
19 | }
20 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Builders/ServiceBuilder.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Builders
14 | {
15 | using Runtime;
16 |
17 | public interface ServiceBuilder
18 | {
19 | ServiceHandle Build(HostSettings settings);
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/HostStartMode.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime
14 | {
15 | public enum HostStartMode
16 | {
17 | Automatic = 0,
18 | Manual = 1,
19 | Disabled = 2,
20 | AutomaticDelayed = 3,
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/EnvironmentBuilderFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using Builders;
16 |
17 | public delegate EnvironmentBuilder EnvironmentBuilderFactory(HostConfigurator configurator);
18 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/ServiceBuilderFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using Builders;
16 | using Runtime;
17 |
18 | public delegate ServiceBuilder ServiceBuilderFactory(HostSettings settings);
19 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Configurators/Configurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Configurators
14 | {
15 | using System.Collections.Generic;
16 |
17 | public interface Configurator
18 | {
19 | IEnumerable Validate();
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/CommandLineParser/ISwitchElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.CommandLineParser
14 | {
15 | interface ISwitchElement :
16 | ICommandLineElement
17 | {
18 | string Key { get; }
19 | bool Value { get; }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/CommandLineParser/IDefinitionElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.CommandLineParser
14 | {
15 | interface IDefinitionElement :
16 | ICommandLineElement
17 | {
18 | string Key { get; }
19 | string Value { get; }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/HostBuilderFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using Builders;
16 | using Runtime;
17 |
18 | public delegate HostBuilder HostBuilderFactory(HostEnvironment environment, HostSettings settings);
19 | }
--------------------------------------------------------------------------------
/template.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | @project@
5 | @build.number@
6 | @authors@
7 | @authors@
8 | @summary@
9 | https://github.com/Topshelf/Topshelf/blob/master/LICENSE
10 | https://github.com/Topshelf/Topshelf
11 | http://topshelf-project.com/wp-content/themes/pandora/slide.1.png
12 | false
13 | @description@
14 | @releaseNotes@
15 | Topshelf
16 | @dependencies@
17 | @references@
18 |
19 | @files@
20 |
--------------------------------------------------------------------------------
/src/Topshelf/Logging/LogWriterOutputProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Logging
14 | {
15 | ///
16 | /// Delegate to provide the log output if the log level is enabled
17 | ///
18 | ///
19 | public delegate object LogWriterOutputProvider();
20 | }
--------------------------------------------------------------------------------
/src/SampleTopshelfService/SampleSansInterfaceService.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace SampleTopshelfService
14 | {
15 | public class SampleSansInterfaceService
16 | {
17 | public void Start()
18 | {
19 | }
20 |
21 | public void Stop()
22 | {
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Configurators/ValidationResultDisposition.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Configurators
14 | {
15 | using System;
16 |
17 | [Serializable]
18 | public enum ValidationResultDisposition
19 | {
20 | Success,
21 | Warning,
22 | Failure,
23 | }
24 | }
--------------------------------------------------------------------------------
/src/Topshelf/HostStartContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | public interface HostStartContext :
16 | HostControl
17 | {
18 | ///
19 | /// If called, prevents the service from starting
20 | ///
21 | void CancelStart();
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/Windows/WindowsUserAccessControl.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 |
14 | namespace Topshelf.Runtime.Windows
15 | {
16 | using Logging;
17 |
18 | public static class WindowsUserAccessControl
19 | {
20 | static readonly LogWriter _log = HostLogger.Get(typeof (WindowsUserAccessControl));
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/InstallHostSettings.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime
14 | {
15 | public interface InstallHostSettings :
16 | HostSettings
17 | {
18 | Credentials Credentials { get; set; }
19 | string[] Dependencies { get; }
20 | HostStartMode StartMode { get; }
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/CommandLineConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using CommandLineParser;
16 | using Options;
17 |
18 | interface CommandLineConfigurator
19 | {
20 | void Configure(ICommandLineElementParser parser);
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Configurators/ConfigurationResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Configurators
14 | {
15 | using System.Collections.Generic;
16 |
17 | public interface ConfigurationResult
18 | {
19 | IEnumerable Results { get; }
20 |
21 | string Message { get; }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Topshelf/ServiceCustomCommand.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | ///
16 | /// Implemented by services that support custom command events
17 | ///
18 | public interface ServiceCustomCommand
19 | {
20 | void CustomCommand(HostControl hostControl, int command);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/LocalSystemOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class LocalSystemOption :
18 | Option
19 | {
20 | public void ApplyTo(HostConfigurator configurator)
21 | {
22 | configurator.RunAsLocalSystem();
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf/ServicePowerEvent.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | ///
16 | /// Implemented by services that support power change events
17 | ///
18 | public interface ServicePowerEvent
19 | {
20 | bool PowerEvent(HostControl hostControl, PowerEventArguments changedArguments);
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/CommandLineParser/Parser.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.CommandLineParser
14 | {
15 | // Reference to further information
16 | //
17 | // http://blogs.msdn.com/lukeh/archive/2007/08/19/monadic-parser-combinators-using-c-3-0.aspx
18 |
19 | delegate Result Parser(TInput input);
20 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/InteractiveOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class InteractiveOption : Option
18 | {
19 | public void ApplyTo(HostConfigurator configurator)
20 | {
21 | configurator.RunAsPrompt();
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/DisabledOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class DisabledOption :
18 | Option
19 | {
20 | public void ApplyTo(HostConfigurator configurator)
21 | {
22 | configurator.Disabled();
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf/ServiceSuspend.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | ///
16 | /// If implemented by a service, used to pause/continue the service
17 | ///
18 | public interface ServiceSuspend
19 | {
20 | bool Pause(HostControl hostControl);
21 | bool Continue(HostControl hostControl);
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/ServiceEvents.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime
14 | {
15 | public interface ServiceEvents
16 | {
17 | void BeforeStart(HostControl hostControl);
18 | void AfterStart(HostControl hostControl);
19 | void BeforeStop(HostControl hostControl);
20 | void AfterStop(HostControl hostControl);
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Topshelf/ServiceSessionChange.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | ///
16 | /// Implemented by services that support session change events
17 | ///
18 | public interface ServiceSessionChange
19 | {
20 | void SessionChange(HostControl hostControl, SessionChangedArguments changedArguments);
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/ManualStartOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class ManualStartOption :
18 | Option
19 | {
20 | public void ApplyTo(HostConfigurator configurator)
21 | {
22 | configurator.StartManually();
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/AutostartOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class AutostartOption :
18 | Option
19 | {
20 | public void ApplyTo(HostConfigurator configurator)
21 | {
22 | configurator.StartAutomatically();
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/DelayedOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class DelayedOption :
18 | Option
19 | {
20 | public void ApplyTo(HostConfigurator configurator)
21 | {
22 | configurator.StartAutomaticallyDelayed();
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/LocalServiceOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class LocalServiceOption :
18 | Option
19 | {
20 | public void ApplyTo(HostConfigurator configurator)
21 | {
22 | configurator.RunAsLocalService();
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/NetworkServiceOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class NetworkServiceOption :
18 | Option
19 | {
20 | public void ApplyTo(HostConfigurator configurator)
21 | {
22 | configurator.RunAsNetworkService();
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf/Host.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | ///
16 | /// A Host can be a number of configured service hosts, from installers to service runners
17 | ///
18 | public interface Host
19 | {
20 | ///
21 | /// Runs the configured host
22 | ///
23 | TopshelfExitCode Run();
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Threading/OperationExecutor.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Threading
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 |
18 | interface OperationExecutor
19 | {
20 | void Execute(Action operation);
21 | void Execute(IList operations, Action> remaining);
22 | void Stop();
23 | }
24 | }
--------------------------------------------------------------------------------
/src/Topshelf/Logging/TraceHostLoggerConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Logging
14 | {
15 | using System;
16 |
17 | [Serializable]
18 | public class TraceHostLoggerConfigurator :
19 | HostLoggerConfigurator
20 | {
21 | public LogWriterFactory CreateLogWriterFactory()
22 | {
23 | return new TraceLogWriterFactory();
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/SystemOnlyHelpOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class SystemOnlyHelpOption :
18 | Option
19 | {
20 | public void ApplyTo(HostConfigurator configurator)
21 | {
22 | configurator.AddConfigurator(new SystemOnlyHelpHostConfigurator());
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/Windows/SCMHandle.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2017 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime.Windows
14 | {
15 | using Microsoft.Win32.SafeHandles;
16 |
17 | public class SCMHandle : SafeHandleZeroOrMinusOneIsInvalid
18 | {
19 | public SCMHandle()
20 | : base(true) { }
21 |
22 | protected override bool ReleaseHandle()
23 | {
24 | return NativeMethods.CloseServiceHandle(handle);
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Scripting/Command.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Scripting
14 | {
15 | using System;
16 |
17 | public interface Command
18 | {
19 | Guid ExecuteId { get; }
20 | Guid CompensateId { get; }
21 |
22 | CommandScriptStepAudit Execute(CommandScriptStep task);
23 | bool Compensate(CommandScriptStepAudit audit, CommandScript commandScript);
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/ServiceAvailabilityHost.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise
14 | {
15 | ///
16 | /// The host for a service availability
17 | ///
18 | public interface ServiceAvailabilityHost
19 | {
20 | ///
21 | /// Stop the service for the reason specified
22 | ///
23 | void StopService(string reason);
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/CommandLineParser/Result.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.CommandLineParser
14 | {
15 | class Result
16 | {
17 | public Result(TValue value, TInput rest)
18 | {
19 | Value = value;
20 | Rest = rest;
21 | }
22 |
23 | public TValue Value { get; private set; }
24 | public TInput Rest { get; private set; }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Topshelf/SessionChangeReasonCode.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | public enum SessionChangeReasonCode
16 | {
17 | ConsoleConnect = 1,
18 | ConsoleDisconnect = 2,
19 | RemoteConnect = 3,
20 | RemoteDisconnect = 4,
21 | SessionLogon = 5,
22 | SessionLogoff = 6,
23 | SessionLock = 7,
24 | SessionUnlock = 8,
25 | SessionRemoteControl = 9,
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Credentials.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2011 The Apache Software Foundation.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using System.ServiceProcess;
16 |
17 |
18 | public class Credentials
19 | {
20 | public Credentials(string username, string password, ServiceAccount account)
21 | {
22 | Username = username;
23 | Account = account;
24 | Password = password;
25 | }
26 |
27 | public string Username { get; set; }
28 | public string Password { get; set; }
29 | public ServiceAccount Account { get; set; }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/Windows/ServiceRecoveryAction.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime.Windows
14 | {
15 | using System;
16 |
17 | public abstract class ServiceRecoveryAction
18 | {
19 | protected ServiceRecoveryAction(int delay)
20 | {
21 | Delay = (int)TimeSpan.FromMinutes(delay).TotalMilliseconds;
22 | }
23 |
24 | public int Delay { get; private set; }
25 |
26 | public abstract NativeMethods.SC_ACTION GetAction();
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/HostBuilderConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using Builders;
16 | using Configurators;
17 |
18 | ///
19 | /// Can configure/replace the input HostBuilder, returning the original
20 | /// or a new HostBuilder
21 | ///
22 | public interface HostBuilderConfigurator :
23 | Configurator
24 | {
25 | HostBuilder Configure(HostBuilder builder);
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/DisplayNameOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class DisplayNameOption : Option
18 | {
19 | string _name;
20 |
21 | public DisplayNameOption(string name)
22 | {
23 | _name = name;
24 | }
25 |
26 | public void ApplyTo(HostConfigurator configurator)
27 | {
28 | configurator.SetDisplayName(_name);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/SudoOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using System;
16 | using HostConfigurators;
17 |
18 | public class SudoOption :
19 | Option
20 | {
21 | public void ApplyTo(HostConfigurator configurator)
22 | {
23 | if (configurator == null)
24 | throw new ArgumentNullException("configurator");
25 |
26 | configurator.AddConfigurator(new SudoConfigurator());
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Topshelf/TopshelfExitCode.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | public enum TopshelfExitCode
16 | {
17 | Ok = 0,
18 | AbnormalExit = 1,
19 | SudoRequired = 2,
20 | ServiceAlreadyInstalled = 3,
21 | ServiceNotInstalled = 4,
22 | StartServiceFailed = 5,
23 | StopServiceFailed = 6,
24 | ServiceAlreadyRunning = 7,
25 | UnhandledServiceException = 8,
26 | ServiceNotRunning = 9,
27 | SendCommandFailed = 10,
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/ServiceNameOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class ServiceNameOption :
18 | Option
19 | {
20 | string _serviceName;
21 |
22 | public ServiceNameOption(string name)
23 | {
24 | _serviceName = name;
25 | }
26 |
27 | public void ApplyTo(HostConfigurator configurator)
28 | {
29 | configurator.SetServiceName(_serviceName);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Threading/ScheduledOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Threading
14 | {
15 | using System;
16 |
17 | interface ScheduledOperation
18 | {
19 | ///
20 | /// The time coordinates when the operation is scheduled to execute
21 | ///
22 | DateTime ScheduledAt { get; }
23 |
24 | ///
25 | /// Cancels the scheduled operation, ensuring that it does not execute
26 | ///
27 | void Cancel();
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/UnknownOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class UnknownOption :
18 | Option
19 | {
20 | readonly string _text;
21 |
22 | public UnknownOption(string text)
23 | {
24 | _text = text;
25 | }
26 |
27 | public void ApplyTo(HostConfigurator configurator)
28 | {
29 | configurator.AddConfigurator(new UnknownCommandLineOptionHostConfigurator(_text));
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/SampleTopshelfSuperviseService/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace SampleTopshelfSuperviseService
14 | {
15 | using Topshelf;
16 |
17 | class Program
18 | {
19 | static int Main()
20 | {
21 | return (int)HostFactory.Run(x =>
22 | {
23 | x.UseLog4Net("log4net.config");
24 |
25 | x.Supervise(s => { s.Service(); });
26 |
27 | x.EnableServiceRecovery(r => { r.RestartService(1); });
28 | });
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/RunOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using System;
16 | using Builders;
17 | using HostConfigurators;
18 |
19 | public class RunOption :
20 | Option
21 | {
22 | public void ApplyTo(HostConfigurator configurator)
23 | {
24 | if (configurator == null)
25 | throw new ArgumentNullException("configurator");
26 |
27 | configurator.UseHostBuilder((environment, settings) => new RunBuilder(environment,settings));
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/ServiceDescriptionOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class ServiceDescriptionOption :
18 | Option
19 | {
20 | string _description;
21 |
22 | public ServiceDescriptionOption(string description)
23 | {
24 | _description = description;
25 | }
26 |
27 | public void ApplyTo(HostConfigurator configurator)
28 | {
29 | configurator.SetDescription(_description);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/HelpOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using System;
16 | using Builders;
17 | using HostConfigurators;
18 |
19 | public class HelpOption :
20 | Option
21 | {
22 | public void ApplyTo(HostConfigurator configurator)
23 | {
24 | if (configurator == null)
25 | throw new ArgumentNullException("configurator");
26 |
27 | configurator.UseHostBuilder((environment, settings) => new HelpBuilder(environment, settings));
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/StartOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using System;
16 | using HostConfigurators;
17 |
18 | public class StartOption :
19 | Option
20 | {
21 | public void ApplyTo(HostConfigurator configurator)
22 | {
23 | if (configurator == null)
24 | throw new ArgumentNullException("configurator");
25 |
26 | var startConfigurator = new StartConfigurator();
27 |
28 | configurator.AddConfigurator(startConfigurator);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/StopOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using System;
16 | using Builders;
17 | using HostConfigurators;
18 |
19 | public class StopOption :
20 | Option
21 | {
22 | public void ApplyTo(HostConfigurator configurator)
23 | {
24 | if (configurator == null)
25 | throw new ArgumentNullException("configurator");
26 |
27 | configurator.UseHostBuilder((environment, settings) => new StopBuilder(environment, settings));
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/StartConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System.Collections.Generic;
16 | using Builders;
17 | using Configurators;
18 |
19 | public class StartConfigurator :
20 | HostBuilderConfigurator
21 | {
22 | public IEnumerable Validate()
23 | {
24 | yield break;
25 | }
26 |
27 | public HostBuilder Configure(HostBuilder builder)
28 | {
29 | return new StartBuilder(builder);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/InstallOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using System;
16 | using Builders;
17 | using HostConfigurators;
18 |
19 | public class InstallOption :
20 | Option
21 | {
22 | public void ApplyTo(HostConfigurator configurator)
23 | {
24 | if (configurator == null)
25 | throw new ArgumentNullException("configurator");
26 |
27 | configurator.UseHostBuilder((environment, settings) => new InstallBuilder(environment, settings));
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/UninstallOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using System;
16 | using Builders;
17 | using HostConfigurators;
18 |
19 | public class UninstallOption :
20 | Option
21 | {
22 | public void ApplyTo(HostConfigurator configurator)
23 | {
24 | if (configurator == null)
25 | throw new ArgumentNullException("configurator");
26 |
27 | configurator.UseHostBuilder((environment, settings) => new UninstallBuilder(environment, settings));
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/ServiceAvailability.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise
14 | {
15 | ///
16 | /// Used to determine if the service is available for the specific operation
17 | ///
18 | public interface ServiceAvailability
19 | {
20 | ///
21 | /// Determines if the service can be started. If the service can not be
22 | /// started, the return is false and the reason is specified.
23 | ///
24 | ///
25 | ///
26 | bool CanStart(out string reason);
27 | }
28 | }
--------------------------------------------------------------------------------
/src/SampleTopshelfSuperviseService/log4net.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Builders/HostBuilder.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Builders
14 | {
15 | using System;
16 | using Runtime;
17 |
18 | ///
19 | /// Using the service configuration, the host builder will create the host
20 | /// that will be ran by the service console.
21 | ///
22 | public interface HostBuilder
23 | {
24 | HostEnvironment Environment { get; }
25 | HostSettings Settings { get; }
26 |
27 | Host Build(ServiceBuilder serviceBuilder);
28 |
29 | void Match(Action callback)
30 | where T : class, HostBuilder;
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/ServiceAccountOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using HostConfigurators;
16 |
17 | public class ServiceAccountOption :
18 | Option
19 | {
20 | readonly string _password;
21 | readonly string _username;
22 |
23 | public ServiceAccountOption(string username, string password)
24 | {
25 | _username = username;
26 | _password = password;
27 | }
28 |
29 | public void ApplyTo(HostConfigurator configurator)
30 | {
31 | configurator.RunAs(_username, _password);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/Windows/WindowsHostEnvironmentBuilder.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime.Windows
14 | {
15 | using Builders;
16 | using HostConfigurators;
17 |
18 | public class WindowsHostEnvironmentBuilder :
19 | EnvironmentBuilder
20 | {
21 | HostConfigurator _hostConfigurator;
22 |
23 | public WindowsHostEnvironmentBuilder(HostConfigurator configurator)
24 | {
25 | _hostConfigurator = configurator;
26 | }
27 |
28 | public HostEnvironment Build()
29 | {
30 | return new WindowsHostEnvironment(_hostConfigurator);
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/Windows/RestartServiceRecoveryAction.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime.Windows
14 | {
15 | public class RestartServiceRecoveryAction :
16 | ServiceRecoveryAction
17 | {
18 | public RestartServiceRecoveryAction(int delay)
19 | : base(delay)
20 | {
21 | }
22 |
23 | public override NativeMethods.SC_ACTION GetAction()
24 | {
25 | return new NativeMethods.SC_ACTION
26 | {
27 | Delay = Delay,
28 | Type = (int)NativeMethods.SC_ACTION_TYPE.RestartService,
29 | };
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Topshelf/ServiceShutdown.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | ///
16 | /// Implemented by services that support service shutdown
17 | ///
18 | public interface ServiceShutdown
19 | {
20 | ///
21 | /// Called when the operating system invokes the service shutdown method. There is little
22 | /// time to react here, but the application try to use RequestAdditionalTime if necessary,
23 | /// but this is really a shut down quick and bail method.
24 | ///
25 | ///
26 | void Shutdown(HostControl hostControl);
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/SystemOnlyHelpHostConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System.Collections.Generic;
16 | using Builders;
17 | using Configurators;
18 |
19 | public class SystemOnlyHelpHostConfigurator :
20 | HostBuilderConfigurator
21 | {
22 | public IEnumerable Validate()
23 | {
24 | yield break;
25 | }
26 |
27 | public HostBuilder Configure(HostBuilder builder)
28 | {
29 | builder.Match(x => x.SystemHelpTextOnly());
30 |
31 | return builder;
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/RestartServiceExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using System;
16 | using Supervise;
17 |
18 | public static class RestartServiceExtensions
19 | {
20 | ///
21 | /// Schedules the service to restart at the specific interval. Useful for services that have known issues and need to be cycled regularly.
22 | ///
23 | ///
24 | /// The interval between restarts
25 | public static void RestartEvery(this SuperviseConfigurator configurator, TimeSpan interval)
26 | {
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/SampleTopshelfService/log4net.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/InstanceOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using System;
16 | using HostConfigurators;
17 |
18 | public class InstanceOption :
19 | Option
20 | {
21 | readonly string _instanceName;
22 |
23 | public InstanceOption(string instanceName)
24 | {
25 | _instanceName = instanceName;
26 | }
27 |
28 | public void ApplyTo(HostConfigurator configurator)
29 | {
30 | if (configurator == null)
31 | throw new ArgumentNullException("configurator");
32 |
33 | configurator.SetInstanceName(_instanceName);
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/src/SampleTopshelfRehabService/log4net.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/EventCallbackList.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 |
18 | public class EventCallbackList
19 | {
20 | readonly IList> _callbacks;
21 |
22 | public EventCallbackList()
23 | {
24 | _callbacks = new List>();
25 | }
26 |
27 | public void Add(Action callback)
28 | {
29 | _callbacks.Add(callback);
30 | }
31 |
32 | public void Notify(T data)
33 | {
34 | foreach (var callback in _callbacks)
35 | {
36 | callback(data);
37 | }
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/src/Topshelf/HostControl.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using System;
16 |
17 | ///
18 | /// Allows the service to control the host while running
19 | ///
20 | public interface HostControl
21 | {
22 | ///
23 | /// Tells the Host that the service is still starting, which resets the
24 | /// timeout.
25 | ///
26 | void RequestAdditionalTime(TimeSpan timeRemaining);
27 |
28 | ///
29 | /// Stops the Host
30 | ///
31 | void Stop();
32 |
33 | ///
34 | /// Restarts the Host
35 | ///
36 | void Restart();
37 | }
38 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Scripting/CommandScriptStepAudit.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Scripting
14 | {
15 | using System;
16 |
17 | public class CommandScriptStepAudit
18 | {
19 | readonly CommandScriptStepResult _result;
20 | readonly Type _type;
21 |
22 | public CommandScriptStepAudit(Command command, CommandScriptStepResult result)
23 | {
24 | _result = result;
25 | _type = command.GetType();
26 | }
27 |
28 | public CommandScriptStepResult Result
29 | {
30 | get { return _result; }
31 | }
32 |
33 | public Type CommandType
34 | {
35 | get { return _type; }
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/Windows/RunProgramRecoveryAction.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime.Windows
14 | {
15 | public class RunProgramRecoveryAction :
16 | ServiceRecoveryAction
17 | {
18 | public RunProgramRecoveryAction(int delay, string command)
19 | : base(delay)
20 | {
21 | Command = command;
22 | }
23 |
24 | public string Command { get; private set; }
25 |
26 | public override NativeMethods.SC_ACTION GetAction()
27 | {
28 | return new NativeMethods.SC_ACTION
29 | {
30 | Delay = Delay,
31 | Type = (int)NativeMethods.SC_ACTION_TYPE.RunCommand,
32 | };
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/SuperviseConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise
14 | {
15 | using HostConfigurators;
16 | using ServiceConfigurators;
17 |
18 | ///
19 | /// Configures the service that is to be supervised, including any of the parameters
20 | /// of the supervision service
21 | ///
22 | public interface SuperviseConfigurator :
23 | ServiceConfigurator
24 | {
25 | ///
26 | /// Sets the service builder to use for creating the service
27 | ///
28 | ///
29 | ///
30 | void UseServiceBuilder(ServiceBuilderFactory serviceBuilderFactory);
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Options/CommandOption.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2014 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Options
14 | {
15 | using System;
16 | using HostConfigurators;
17 |
18 |
19 | public class CommandOption :
20 | Option
21 | {
22 | readonly int _command;
23 |
24 | public CommandOption(string command)
25 | {
26 | _command = int.Parse(command);
27 | }
28 |
29 | public void ApplyTo(HostConfigurator configurator)
30 | {
31 | if (configurator == null)
32 | throw new ArgumentNullException("configurator");
33 |
34 | var commandConfigurator = new CommandConfigurator(_command);
35 |
36 | configurator.AddConfigurator(commandConfigurator);
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/src/Topshelf/Exceptions/TopshelfException.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using System;
16 | using System.Runtime.Serialization;
17 |
18 | [Serializable]
19 | public class TopshelfException :
20 | Exception
21 | {
22 | public TopshelfException()
23 | {
24 | }
25 |
26 | public TopshelfException(string message)
27 | : base(message)
28 | {
29 | }
30 |
31 | public TopshelfException(string message, Exception innerException)
32 | : base(message, innerException)
33 | {
34 | }
35 |
36 | protected TopshelfException(SerializationInfo info, StreamingContext context)
37 | : base(info, context)
38 | {
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/Windows/RestartSystemRecoveryAction.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime.Windows
14 | {
15 | public class RestartSystemRecoveryAction :
16 | ServiceRecoveryAction
17 | {
18 | public RestartSystemRecoveryAction(int delay, string restartMessage)
19 | : base(delay)
20 | {
21 | RestartMessage = restartMessage;
22 | }
23 |
24 | public string RestartMessage { get; private set; }
25 |
26 | public override NativeMethods.SC_ACTION GetAction()
27 | {
28 | return new NativeMethods.SC_ACTION
29 | {
30 | Delay = Delay,
31 | Type = (int)NativeMethods.SC_ACTION_TYPE.RebootComputer,
32 | };
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/doc/source/installation/install.rst:
--------------------------------------------------------------------------------
1 | Installing Topshelf
2 | ===================
3 |
4 | NuGet
5 | '''''
6 |
7 | The simplest way to install Topshelf into your solution/project is to use
8 | NuGet.::
9 |
10 | nuget Install-Package Topshelf
11 |
12 |
13 | Raw Binaries
14 | ''''''''''''
15 |
16 | If you are a fan of getting the binaries you can get released builds from
17 |
18 | http://github.com/topshelf/Topshelf/downloads
19 |
20 | Then you will need to add references to
21 | =======================================
22 |
23 | * Topshelf.dll
24 |
25 |
26 | Compiling From Source
27 | '''''''''''''''''''''
28 |
29 | Lastly, if you want to hack on Topshelf or just want to have the actual source
30 | code you can clone the source from github.com.
31 |
32 | To clone the repository using git try the following::
33 |
34 | git clone git://github.com/Topshelf/Topshelf.git
35 |
36 | If you want the development branch (where active development happens)::
37 |
38 | git clone git://github.com/Topshelf/Topshelf.git
39 | git checkout develop
40 |
41 | Build Dependencies
42 | ''''''''''''''''''
43 |
44 | To compile Topshelf from source you will need the following developer tools
45 | installed:
46 |
47 | * .Net 4.0 sdk
48 | * ruby v 1.8.7
49 | * gems (rake, albacore)
50 |
51 | Compiling
52 | '''''''''
53 |
54 | To compile the source code, drop to the command line and type::
55 |
56 | .\build.bat
57 |
58 | If you look in the ``.\build_output`` folder you should see the binaries.
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/TestHostExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using Builders;
16 | using HostConfigurators;
17 |
18 | public static class TestHostExtensions
19 | {
20 | ///
21 | /// Configures the test host, which simply starts and stops the service. Meant to be used
22 | /// to verify the service can be created, started, stopped, and disposed without issues.
23 | ///
24 | public static HostConfigurator UseTestHost(this HostConfigurator configurator)
25 | {
26 | configurator.UseHostBuilder((environment, settings) => new TestBuilder(environment, settings));
27 | configurator.ApplyCommandLine("");
28 |
29 | return configurator;
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/SampleTopshelfRehabService/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace SampleTopshelfRehabService
14 | {
15 | using Topshelf;
16 |
17 | class Program
18 | {
19 | static int Main()
20 | {
21 | return (int)HostFactory.Run(x =>
22 | {
23 | x.UseLog4Net("log4net.config");
24 |
25 | x.Service();
26 |
27 | // this will enable Pause and Continue, may break this out into a separate interface to
28 | // reduce the footprint on the service code if pause and continue are not supported.
29 | x.EnablePauseAndContinue();
30 |
31 | x.EnableServiceRecovery(r => { r.RestartService(1); });
32 | });
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Topshelf.Rehab/AppDomainHostControl.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Rehab
14 | {
15 | using System;
16 |
17 | public class AppDomainHostControl :
18 | MarshalByRefObject,
19 | HostControl
20 | {
21 | readonly HostControl _hostControl;
22 |
23 | public AppDomainHostControl(HostControl hostControl)
24 | {
25 | _hostControl = hostControl;
26 | }
27 |
28 | public void RequestAdditionalTime(TimeSpan timeRemaining)
29 | {
30 | _hostControl.RequestAdditionalTime(timeRemaining);
31 | }
32 |
33 | public void Stop()
34 | {
35 | _hostControl.Stop();
36 | }
37 |
38 | public void Restart()
39 | {
40 | _hostControl.Restart();
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/src/Topshelf/Exceptions/ServiceBuilderException.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using System;
16 | using System.Runtime.Serialization;
17 |
18 | [Serializable]
19 | public class ServiceBuilderException :
20 | TopshelfException
21 | {
22 | public ServiceBuilderException()
23 | {
24 | }
25 |
26 | public ServiceBuilderException(string message)
27 | : base(message)
28 | {
29 | }
30 |
31 | public ServiceBuilderException(string message, Exception innerException)
32 | : base(message, innerException)
33 | {
34 | }
35 |
36 | protected ServiceBuilderException(SerializationInfo info, StreamingContext context)
37 | : base(info, context)
38 | {
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/SudoConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 | using Builders;
18 | using Configurators;
19 |
20 | public class SudoConfigurator :
21 | HostBuilderConfigurator
22 | {
23 | public IEnumerable Validate()
24 | {
25 | yield break;
26 | }
27 |
28 | public HostBuilder Configure(HostBuilder builder)
29 | {
30 | if (builder == null)
31 | throw new ArgumentNullException("builder");
32 |
33 | builder.Match(x => x.Sudo());
34 | builder.Match(x => x.Sudo());
35 |
36 | return builder;
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/src/Topshelf/Exceptions/HostConfigurationException.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using System;
16 | using System.Runtime.Serialization;
17 |
18 | [Serializable]
19 | public class HostConfigurationException :
20 | TopshelfException
21 | {
22 | public HostConfigurationException()
23 | {
24 | }
25 |
26 | public HostConfigurationException(string message)
27 | : base(message)
28 | {
29 | }
30 |
31 | public HostConfigurationException(string message, Exception innerException)
32 | : base(message, innerException)
33 | {
34 | }
35 |
36 | protected HostConfigurationException(SerializationInfo info, StreamingContext context)
37 | : base(info, context)
38 | {
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/CommandLineParser/AbstractParser.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.CommandLineParser
14 | {
15 | using System.Linq;
16 |
17 | abstract class AbstractParser
18 | {
19 | public Parser Succeed(TValue value)
20 | {
21 | return input => new Result(value, input);
22 | }
23 |
24 | public Parser Rep(Parser parser)
25 | {
26 | return Rep1(parser).Or(Succeed(new TValue[0]));
27 | }
28 |
29 | public Parser Rep1(Parser parser)
30 | {
31 | return from x in parser
32 | from xs in Rep(parser)
33 | select (new[] {x}).Concat(xs).ToArray();
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/Windows/ServiceRecoveryOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime.Windows
14 | {
15 | using System.Collections.Generic;
16 |
17 | public class ServiceRecoveryOptions
18 | {
19 | readonly IList _actions;
20 |
21 | public ServiceRecoveryOptions()
22 | {
23 | _actions = new List();
24 | }
25 |
26 | public int ResetPeriod { get; set; }
27 |
28 | public IEnumerable Actions
29 | {
30 | get { return _actions; }
31 | }
32 |
33 | public bool RecoverOnCrashOnly { get; set; }
34 |
35 | public void AddAction(ServiceRecoveryAction serviceRecoveryAction)
36 | {
37 | _actions.Add(serviceRecoveryAction);
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/UnknownCommandLineOptionHostConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System.Collections.Generic;
16 | using Builders;
17 | using Configurators;
18 |
19 | public class UnknownCommandLineOptionHostConfigurator :
20 | HostBuilderConfigurator
21 | {
22 | readonly string _text;
23 |
24 | public UnknownCommandLineOptionHostConfigurator(string text)
25 | {
26 | _text = text;
27 | }
28 |
29 | public IEnumerable Validate()
30 | {
31 | yield return this.Failure("Command Line", "An unknown command-line option was found: " + _text);
32 | }
33 |
34 | public HostBuilder Configure(HostBuilder builder)
35 | {
36 | return builder;
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/CommandConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2014 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System.Collections.Generic;
16 | using Builders;
17 | using Configurators;
18 |
19 |
20 | public class CommandConfigurator :
21 | HostBuilderConfigurator
22 | {
23 | readonly int _command;
24 |
25 | public CommandConfigurator(int command)
26 | {
27 | _command = command;
28 | }
29 |
30 | public IEnumerable Validate()
31 | {
32 | if (_command < 128 || _command > 256)
33 | yield return this.Failure("Command", "must be between 128 and 256");
34 | }
35 |
36 | public HostBuilder Configure(HostBuilder builder)
37 | {
38 | return new CommandBuilder(builder, _command);
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/HostControlProxy.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise
14 | {
15 | using System;
16 |
17 | ///
18 | /// This proxy is used to keep remoting to other app domains clean
19 | ///
20 | public class HostControlProxy :
21 | MarshalByRefObject,
22 | HostControl
23 | {
24 | readonly HostControl _hostControl;
25 |
26 | public HostControlProxy(HostControl hostControl)
27 | {
28 | _hostControl = hostControl;
29 | }
30 |
31 | public void RequestAdditionalTime(TimeSpan timeRemaining)
32 | {
33 | _hostControl.RequestAdditionalTime(timeRemaining);
34 | }
35 |
36 | public void Stop()
37 | {
38 | _hostControl.Stop();
39 | }
40 |
41 | public void Restart()
42 | {
43 | _hostControl.Restart();
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/ServiceRecoveryConfiguratorExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using System;
16 | using HostConfigurators;
17 |
18 | public static class ServiceRecoveryConfiguratorExtensions
19 | {
20 | public static HostConfigurator EnableServiceRecovery(this HostConfigurator configurator, Action configureCallback)
21 | {
22 | if (configurator == null)
23 | throw new ArgumentNullException("configurator");
24 | if (configureCallback == null)
25 | throw new ArgumentNullException("configureCallback");
26 |
27 | var recoveryHostConfigurator = new ServiceRecoveryHostConfigurator();
28 |
29 | configureCallback(recoveryHostConfigurator);
30 |
31 | configurator.AddConfigurator(recoveryHostConfigurator);
32 |
33 | return configurator;
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Threading/ScheduledOperationExecuterImpl.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Threading
14 | {
15 | using System;
16 |
17 | class ScheduledOperationExecuterImpl :
18 | ScheduledOperationExecuter
19 | {
20 | readonly Fiber _fiber;
21 | readonly Action _operation;
22 | bool _cancelled;
23 |
24 | public ScheduledOperationExecuterImpl(DateTime scheduledAt, Fiber fiber, Action operation)
25 | {
26 | ScheduledAt = scheduledAt;
27 | _fiber = fiber;
28 | _operation = operation;
29 | }
30 |
31 | public DateTime ScheduledAt { get; set; }
32 |
33 | public void Cancel()
34 | {
35 | _cancelled = true;
36 | }
37 |
38 | public void Execute()
39 | {
40 | if (_cancelled)
41 | return;
42 |
43 | _fiber.Add(_operation);
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Threading/Fiber.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Threading
14 | {
15 | using System;
16 |
17 | interface Fiber
18 | {
19 | ///
20 | /// Enqueue a single action to the queue
21 | ///
22 | ///
23 | void Add(Action operation);
24 |
25 | ///
26 | /// Runs all remaining actions, waiting until all actions have been executed or until the
27 | /// timeout expires. If the timeout expires, an exception is thrown.
28 | ///
29 | /// The time to wait for all pending actions to be executed before throwing an exception
30 | void Shutdown(TimeSpan timeout);
31 |
32 | ///
33 | /// Stops the fiber, discards any remaining actions, and prevents new actions from being added
34 | ///
35 | void Stop();
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/RunAsVirtualAccountHostConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 | using System.ServiceProcess;
18 | using Builders;
19 | using Configurators;
20 |
21 |
22 | public class RunAsVirtualAccountHostConfigurator :
23 | HostBuilderConfigurator
24 | {
25 | public RunAsVirtualAccountHostConfigurator()
26 | {
27 | }
28 |
29 | public HostBuilder Configure(HostBuilder builder)
30 | {
31 | if (builder == null)
32 | throw new ArgumentNullException("builder");
33 |
34 | builder.Match(x => x.RunAs("NT SERVICE\\" + x.Settings.ServiceName, "", ServiceAccount.User));
35 |
36 | return builder;
37 | }
38 |
39 | public IEnumerable Validate()
40 | {
41 | yield break;
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/src/Topshelf/Logging/TopshelfConsoleTraceListener.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Logging
14 | {
15 | using System;
16 | using System.Diagnostics;
17 |
18 | public class TopshelfConsoleTraceListener :
19 | TraceListener
20 | {
21 | public override void Write(string message)
22 | {
23 | Console.Write(message);
24 | }
25 |
26 | public override void WriteLine(string message)
27 | {
28 | Console.WriteLine(message);
29 | }
30 |
31 | public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id,
32 | string message)
33 | {
34 | WriteLine(message);
35 | }
36 |
37 | public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id,
38 | string format, params object[] args)
39 | {
40 | WriteLine(string.Format(format, args));
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Scripting/CommandScriptStep.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Scripting
14 | {
15 | using System;
16 |
17 | public interface CommandScriptStep
18 | {
19 | CommandScript CommandScript { get; set; }
20 | CommandScriptStepArguments Arguments { get; }
21 | Type ActivityType { get; }
22 | }
23 |
24 | public class CommandScriptStep :
25 | CommandScriptStep
26 | where T : Command
27 | {
28 | public CommandScriptStep()
29 | {
30 | Arguments = new CommandScriptStepArguments();
31 | }
32 |
33 | public CommandScriptStep(CommandScriptStepArguments arguments)
34 | {
35 | Arguments = arguments;
36 | }
37 |
38 | public CommandScript CommandScript { get; set; }
39 |
40 | public CommandScriptStepArguments Arguments { get; private set; }
41 |
42 | public Type ActivityType
43 | {
44 | get { return typeof(T); }
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/Threading/FiberExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise.Threading
14 | {
15 | using System;
16 | using System.Threading;
17 |
18 | static class FiberExtensions
19 | {
20 | public static bool AddAndWait(this Fiber fiber, Action operation, TimeSpan timeout)
21 | {
22 | var @event = new ManualResetEvent(false);
23 |
24 | fiber.Add(() =>
25 | {
26 | try
27 | {
28 | operation();
29 | }
30 | finally
31 | {
32 | @event.Set();
33 | }
34 | });
35 |
36 | bool completed = @event.WaitOne(timeout);
37 | fiber.Add(() =>
38 | {
39 | var disposable = @event as IDisposable;
40 | disposable.Dispose();
41 | });
42 |
43 | return completed;
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/src/Topshelf.Rehab/RehabServiceBuilder.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Rehab
14 | {
15 | using System;
16 | using Builders;
17 | using HostConfigurators;
18 | using Runtime;
19 |
20 | public class RehabServiceBuilder :
21 | ServiceBuilder
22 | where T : class
23 | {
24 | readonly ServiceBuilderFactory _serviceBuilderFactory;
25 |
26 | public RehabServiceBuilder(ServiceBuilderFactory serviceBuilderFactory)
27 | {
28 | _serviceBuilderFactory = serviceBuilderFactory;
29 | }
30 |
31 | public ServiceHandle Build(HostSettings settings)
32 | {
33 | try
34 | {
35 | ServiceHandle handle = new RehabServiceHandle(settings, _serviceBuilderFactory);
36 |
37 |
38 | return handle;
39 | }
40 | catch (Exception ex)
41 | {
42 | throw new ServiceBuilderException("An exception occurred creating the service: " + typeof(T).Name, ex);
43 | }
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/ServiceConfigurators/ControlServiceConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.ServiceConfigurators
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 | using Builders;
18 | using Configurators;
19 | using Runtime;
20 |
21 | public class ControlServiceConfigurator :
22 | ServiceConfiguratorBase,
23 | ServiceConfigurator,
24 | Configurator
25 | where T : class, ServiceControl
26 | {
27 | readonly Func _serviceFactory;
28 |
29 | public ControlServiceConfigurator(Func serviceFactory)
30 | {
31 | _serviceFactory = serviceFactory;
32 | }
33 |
34 | public IEnumerable Validate()
35 | {
36 | yield break;
37 | }
38 |
39 |
40 | public ServiceBuilder Build()
41 | {
42 | var serviceBuilder = new ControlServiceBuilder(_serviceFactory, ServiceEvents);
43 | return serviceBuilder;
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/src/SolutionVersion.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System.Reflection;
3 |
4 | [assembly: AssemblyTitleAttribute("Topshelf")]
5 | [assembly: AssemblyDescriptionAttribute("Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.")]
6 | [assembly: AssemblyProductAttribute("Topshelf")]
7 | [assembly: AssemblyVersionAttribute("4.0.0.0")]
8 | [assembly: AssemblyFileVersionAttribute("4.0.3.0")]
9 | [assembly: AssemblyInformationalVersionAttribute("4.0.3.0 (develop/0b352d8c)")]
10 | [assembly: AssemblyCopyrightAttribute("Copyright 2012 Chris Patterson, Dru Sellers, Travis Smith, All rights reserved.")]
11 | namespace System {
12 | internal static class AssemblyVersionInformation {
13 | internal const System.String AssemblyTitle = "Topshelf";
14 | internal const System.String AssemblyDescription = "Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.";
15 | internal const System.String AssemblyProduct = "Topshelf";
16 | internal const System.String AssemblyVersion = "4.0.0.0";
17 | internal const System.String AssemblyFileVersion = "4.0.3.0";
18 | internal const System.String AssemblyInformationalVersion = "4.0.3.0 (develop/0b352d8c)";
19 | internal const System.String AssemblyCopyright = "Copyright 2012 Chris Patterson, Dru Sellers, Travis Smith, All rights reserved.";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Topshelf.Elmah/ElmahConfigurationExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using HostConfigurators;
16 | using Logging;
17 |
18 | ///
19 | /// Extensions for configuring Logging for log4net
20 | ///
21 | public static class ElmahConfigurationExtensions
22 | {
23 | ///
24 | /// Specify that you want to use the Elmah logging engine.
25 | ///
26 | ///
27 | public static void UseElmah(this HostConfigurator configurator)
28 | {
29 | ElmahLogWriterFactory.Use();
30 | }
31 |
32 | ///
33 | /// Specify that you want to use the Elmah logging engine.
34 | ///
35 | ///
36 | /// The desired level of elmah logging
37 | public static void UseElmah(this HostConfigurator configurator, ElmahLogLevels logLevels)
38 | {
39 | ElmahLogWriterFactory.Use(logLevels);
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/SuperviseServiceConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Supervise
14 | {
15 | using System.Collections.Generic;
16 | using Builders;
17 | using Configurators;
18 | using HostConfigurators;
19 | using ServiceConfigurators;
20 |
21 | public class SuperviseServiceConfigurator :
22 | ServiceConfiguratorBase,
23 | SuperviseConfigurator,
24 | Configurator
25 | {
26 | ServiceBuilderFactory _serviceBuilderFactory;
27 |
28 | public IEnumerable Validate()
29 | {
30 | if (_serviceBuilderFactory == null)
31 | yield return this.Failure("ServiceBuilderFactory", "must not be null");
32 | }
33 |
34 | public void UseServiceBuilder(ServiceBuilderFactory serviceBuilderFactory)
35 | {
36 | _serviceBuilderFactory = serviceBuilderFactory;
37 | }
38 |
39 | public ServiceBuilder Build()
40 | {
41 | return new SuperviseServiceBuilder(_serviceBuilderFactory, ServiceEvents);
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Configurators/ValidateResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Configurators
14 | {
15 | ///
16 | /// Reports information about the configuration before configuring
17 | /// so that corrections can be made without allocating resources, etc.
18 | ///
19 | public interface ValidateResult
20 | {
21 | ///
22 | /// The disposition of the result, any Failure items will prevent
23 | /// the configuration from completing.
24 | ///
25 | ValidationResultDisposition Disposition { get; }
26 |
27 | ///
28 | /// The message associated with the result
29 | ///
30 | string Message { get; }
31 |
32 | ///
33 | /// The key associated with the result (chained if configurators are nested)
34 | ///
35 | string Key { get; }
36 |
37 | ///
38 | /// The value associated with the result
39 | ///
40 | string Value { get; }
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/RunAsServiceAccountHostConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 | using System.ServiceProcess;
18 | using Builders;
19 | using Configurators;
20 |
21 |
22 | public class RunAsServiceAccountHostConfigurator :
23 | HostBuilderConfigurator
24 | {
25 | public RunAsServiceAccountHostConfigurator(ServiceAccount accountType)
26 | {
27 | AccountType = accountType;
28 | }
29 |
30 | public ServiceAccount AccountType { get; private set; }
31 |
32 | public HostBuilder Configure(HostBuilder builder)
33 | {
34 | if (builder == null)
35 | throw new ArgumentNullException("builder");
36 |
37 | builder.Match(x => x.RunAs("", "", AccountType));
38 |
39 | return builder;
40 | }
41 |
42 | public IEnumerable Validate()
43 | {
44 | yield break;
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/RunHostConfiguratorAction.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 | using Builders;
18 | using Configurators;
19 |
20 | public class RunHostConfiguratorAction :
21 | HostBuilderConfigurator
22 | {
23 | readonly Action _callback;
24 | readonly string _key;
25 |
26 | public RunHostConfiguratorAction(string key, Action callback)
27 | {
28 | _key = key;
29 | _callback = callback;
30 | }
31 |
32 | public HostBuilder Configure(HostBuilder builder)
33 | {
34 | if (builder == null)
35 | throw new ArgumentNullException("builder");
36 |
37 | builder.Match(x => _callback(x));
38 |
39 | return builder;
40 | }
41 |
42 | public IEnumerable Validate()
43 | {
44 | if (_callback == null)
45 | yield return this.Failure(_key, "must not be null");
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/ServiceConfigurators/ServiceConfiguratorBase.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.ServiceConfigurators
14 | {
15 | using System;
16 | using Runtime;
17 |
18 | public abstract class ServiceConfiguratorBase
19 | {
20 | protected readonly ServiceEventsImpl ServiceEvents;
21 |
22 | protected ServiceConfiguratorBase()
23 | {
24 | ServiceEvents = new ServiceEventsImpl();
25 | }
26 |
27 | public void BeforeStartingService(Action callback)
28 | {
29 | ServiceEvents.AddBeforeStart(callback);
30 | }
31 |
32 | public void AfterStartingService(Action callback)
33 | {
34 | ServiceEvents.AddAfterStart(callback);
35 | }
36 |
37 | public void BeforeStoppingService(Action callback)
38 | {
39 | ServiceEvents.AddBeforeStop(callback);
40 | }
41 |
42 | public void AfterStoppingService(Action callback)
43 | {
44 | ServiceEvents.AddAfterStop(callback);
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/UninstallHostConfiguratorExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using System;
16 | using HostConfigurators;
17 |
18 | public static class UninstallHostConfiguratorExtensions
19 | {
20 | public static HostConfigurator BeforeUninstall(this HostConfigurator configurator, Action callback)
21 | {
22 | if (configurator == null)
23 | throw new ArgumentNullException("configurator");
24 |
25 | configurator.AddConfigurator(new UninstallHostConfiguratorAction("BeforeUninstall",
26 | x => x.BeforeUninstall(callback)));
27 |
28 | return configurator;
29 | }
30 |
31 | public static HostConfigurator AfterUninstall(this HostConfigurator configurator, Action callback)
32 | {
33 | if (configurator == null)
34 | throw new ArgumentNullException("configurator");
35 |
36 | configurator.AddConfigurator(new UninstallHostConfiguratorAction("AfterUninstall",
37 | x => x.AfterUninstall(callback)));
38 |
39 | return configurator;
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Constants/KnownServiceNames.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Constants
14 | {
15 | ///
16 | /// A selection of commonly-used Windows services.
17 | ///
18 | public static class KnownServiceNames
19 | {
20 | ///
21 | /// The Microsoft Message Queue service.
22 | ///
23 | public static string Msmq
24 | {
25 | get { return "MSMQ"; }
26 | }
27 |
28 | ///
29 | /// The Microsoft SQL Server service.
30 | ///
31 | public static string SqlServer
32 | {
33 | get { return "MSSQLSERVER"; }
34 | }
35 |
36 | ///
37 | /// The Internet Information Server service.
38 | ///
39 | public static string IIS
40 | {
41 | get { return "W3SVC"; }
42 | }
43 |
44 | ///
45 | /// The Event Log service.
46 | ///
47 | public static string EventLog
48 | {
49 | get { return "Eventlog"; }
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/src/Topshelf.NLog/NLogConfiguratorExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using HostConfigurators;
16 | using Logging;
17 | using NLog;
18 |
19 | ///
20 | /// Extensions for configuring NLog with MassTransit
21 | ///
22 | public static class NLogConfiguratorExtensions
23 | {
24 | ///
25 | /// Specify that you want to use the NLog logging framework.
26 | ///
27 | /// Optional service bus configurator
28 | public static void UseNLog(this HostConfigurator configurator)
29 | {
30 | NLogLogWriterFactory.Use();
31 | }
32 |
33 | ///
34 | /// Specify that you want to use the NLog logging framework.
35 | ///
36 | /// Optional service bus configurator
37 | /// Required log-producing factory from NLog
38 | public static void UseNLog(this HostConfigurator configurator, LogFactory factory)
39 | {
40 | NLogLogWriterFactory.Use(factory);
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/UninstallHostConfiguratorAction.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 | using Builders;
18 | using Configurators;
19 |
20 |
21 | public class UninstallHostConfiguratorAction :
22 | HostBuilderConfigurator
23 | {
24 | public UninstallHostConfiguratorAction(string key, Action callback)
25 | {
26 | Key = key;
27 | Callback = callback;
28 | }
29 |
30 | public Action Callback { get; private set; }
31 | public string Key { get; private set; }
32 |
33 | public HostBuilder Configure(HostBuilder builder)
34 | {
35 | if (builder == null)
36 | throw new ArgumentNullException("builder");
37 |
38 | builder.Match(x => Callback(x));
39 |
40 | return builder;
41 | }
42 |
43 | public IEnumerable Validate()
44 | {
45 | if (Callback == null)
46 | yield return this.Failure(Key, "must not be null");
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/StartModeHostConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 | using Builders;
18 | using Configurators;
19 | using Runtime;
20 |
21 |
22 | public class StartModeHostConfigurator :
23 | HostBuilderConfigurator
24 | {
25 | public StartModeHostConfigurator(HostStartMode startMode)
26 | {
27 | StartMode = startMode;
28 | }
29 |
30 | public HostStartMode StartMode { get; private set; }
31 |
32 | public IEnumerable Validate()
33 | {
34 | #if NET35
35 | if (StartMode == HostStartMode.AutomaticDelayed)
36 | yield return this.Failure("StartMode", "Automatic (Delayed) is only available on .NET 4.0 or later");
37 | #endif
38 | yield break;
39 | }
40 |
41 | public HostBuilder Configure(HostBuilder builder)
42 | {
43 | if (builder == null)
44 | throw new ArgumentNullException("builder");
45 |
46 | builder.Match(x => x.SetStartMode(StartMode));
47 |
48 | return builder;
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/src/Topshelf/Exceptions/ServiceControlException.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using System;
16 | using System.Runtime.Serialization;
17 |
18 | [Serializable]
19 | public class ServiceControlException :
20 | TopshelfException
21 | {
22 | public ServiceControlException()
23 | {
24 | }
25 |
26 | public ServiceControlException(string message)
27 | : base(message)
28 | {
29 | }
30 |
31 | public ServiceControlException(string message, Exception innerException)
32 | : base(message, innerException)
33 | {
34 | }
35 |
36 | protected ServiceControlException(SerializationInfo info, StreamingContext context)
37 | : base(info, context)
38 | {
39 | }
40 |
41 | public ServiceControlException(string format, Type serviceType, string command, Exception innerException)
42 | : this(FormatMessage(format, serviceType, command), innerException)
43 | {
44 |
45 | }
46 |
47 | static string FormatMessage(string format, Type serviceType, string command)
48 | {
49 | return string.Format(format, serviceType, command);
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/src/SampleTopshelfSuperviseService/PoorlyBehavedService.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace SampleTopshelfSuperviseService
14 | {
15 | using System;
16 | using System.Threading;
17 | using Topshelf;
18 | using Topshelf.Logging;
19 |
20 | public class PoorlyBehavedService :
21 | ServiceControl
22 | {
23 | readonly LogWriter _log = HostLogger.Get();
24 |
25 | public bool Start(HostControl hostControl)
26 | {
27 | Console.WriteLine("I exhibit bad behavior, but I started on command.");
28 |
29 | ThreadPool.QueueUserWorkItem(x =>
30 | {
31 | Thread.Sleep(5000);
32 |
33 | _log.Info("Stopping for no particular reason");
34 |
35 | hostControl.Stop();
36 |
37 | // _log.Info("Dying an ungraceful death");
38 | //
39 | // throw new InvalidOperationException("Oh, what a world.");
40 | });
41 |
42 | return true;
43 | }
44 |
45 | public bool Stop(HostControl hostControl)
46 | {
47 | Console.WriteLine("I'm not bad, I'm just coded that way. So I'm stopped.");
48 |
49 | return true;
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/src/Topshelf.Tests/BeforeStart_Specs.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Tests
14 | {
15 | using NUnit.Framework;
16 |
17 |
18 | [TestFixture]
19 | public class When_the_service_start_is_canceled
20 | {
21 | [Test]
22 | public void Should_not_start_the_service()
23 | {
24 | bool started = false;
25 |
26 | var exitCode = HostFactory.Run(x =>
27 | {
28 | x.UseTestHost();
29 |
30 | x.Service(settings => new MyService(), s =>
31 | {
32 | s.BeforeStartingService(hsc => hsc.CancelStart());
33 | s.AfterStartingService(hsc => { started = true; });
34 | });
35 | });
36 |
37 | Assert.IsFalse(started);
38 | Assert.AreEqual(TopshelfExitCode.StartServiceFailed, exitCode);
39 | }
40 |
41 |
42 | class MyService : ServiceControl
43 | {
44 | public bool Start(HostControl hostControl)
45 | {
46 | return true;
47 | }
48 |
49 | public bool Stop(HostControl hostControl)
50 | {
51 | return true;
52 | }
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/DependencyHostConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 | using Builders;
18 | using Configurators;
19 |
20 |
21 | ///
22 | /// Adds a dependency to the InstallBuilder (ignored otherwise)
23 | ///
24 | public class DependencyHostConfigurator :
25 | HostBuilderConfigurator
26 | {
27 | public DependencyHostConfigurator(string name)
28 | {
29 | if (name == null)
30 | throw new ArgumentNullException("name");
31 |
32 | Name = name;
33 | }
34 |
35 | public string Name { get; private set; }
36 |
37 | public IEnumerable Validate()
38 | {
39 | if (string.IsNullOrEmpty(Name))
40 | yield return this.Failure("Dependency", "must not be null");
41 | }
42 |
43 | public HostBuilder Configure(HostBuilder builder)
44 | {
45 | if (builder == null)
46 | throw new ArgumentNullException("builder");
47 |
48 | builder.Match(x => x.AddDependency(Name));
49 |
50 | return builder;
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/src/Topshelf.Serilog/Logging/SerilogLogWriterFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2015 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Logging
14 | {
15 | using System;
16 | using Serilog;
17 |
18 | public class SerilogLogWriterFactory : LogWriterFactory
19 | {
20 | readonly Func _loggerFactory;
21 |
22 | SerilogLogWriterFactory(ILogger logger)
23 | {
24 | _loggerFactory = name => logger.ForContext("SourceContext", name);
25 | }
26 |
27 | public LogWriter Get(string name)
28 | {
29 | return new SerilogLogWriter(_loggerFactory(name));
30 | }
31 |
32 | public void Shutdown()
33 | {
34 | }
35 |
36 | public static void Use(ILogger logger)
37 | {
38 | HostLogger.UseLogger(new SerilogHostLoggerConfigurator(logger));
39 | }
40 |
41 | [Serializable]
42 | public class SerilogHostLoggerConfigurator : HostLoggerConfigurator
43 | {
44 | readonly ILogger _logger;
45 |
46 | public SerilogHostLoggerConfigurator(ILogger logger)
47 | {
48 | _logger = logger;
49 | }
50 |
51 | public LogWriterFactory CreateLogWriterFactory()
52 | {
53 | return new SerilogLogWriterFactory(_logger);
54 | }
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/src/Topshelf/Runtime/Windows/Kernel32.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Runtime.Windows
14 | {
15 | using System;
16 | using System.Runtime.InteropServices;
17 |
18 | static class Kernel32
19 | {
20 | public static uint TH32CS_SNAPPROCESS = 2;
21 |
22 | [StructLayout(LayoutKind.Sequential)]
23 | public struct PROCESSENTRY32
24 | {
25 | public uint dwSize;
26 | public uint cntUsage;
27 | public uint th32ProcessID;
28 | public IntPtr th32DefaultHeapID;
29 | public uint th32ModuleID;
30 | public uint cntThreads;
31 | public uint th32ParentProcessID;
32 | public int pcPriClassBase;
33 | public uint dwFlags;
34 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szExeFile;
35 | } ;
36 |
37 | [DllImport("kernel32.dll", SetLastError = true)]
38 | public static extern IntPtr CreateToolhelp32Snapshot(uint dwFlags, uint th32ProcessID);
39 |
40 | [DllImport("kernel32.dll")]
41 | public static extern bool Process32First(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
42 |
43 | [DllImport("kernel32.dll")]
44 | public static extern bool Process32Next(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
45 | }
46 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/InstallHostConfiguratorAction.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 | using Builders;
18 | using Configurators;
19 |
20 |
21 | public class InstallHostConfiguratorAction :
22 | HostBuilderConfigurator
23 | {
24 | public InstallHostConfiguratorAction(string key, Action callback)
25 | {
26 | if (callback == null)
27 | throw new ArgumentNullException("callback");
28 |
29 | Key = key;
30 | Callback = callback;
31 | }
32 |
33 | public Action Callback { get; private set; }
34 | public string Key { get; private set; }
35 |
36 | public IEnumerable Validate()
37 | {
38 | if (Callback == null)
39 | yield return this.Failure(Key, "A null callback was specified");
40 | }
41 |
42 | public HostBuilder Configure(HostBuilder builder)
43 | {
44 | if (builder == null)
45 | throw new ArgumentNullException("builder");
46 |
47 | builder.Match(x => Callback(x));
48 |
49 | return builder;
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/src/Topshelf.Elmah/Logging/ElmahLogWriterFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Logging
14 | {
15 | using System;
16 | using Elmah;
17 |
18 | public class ElmahLogWriterFactory :
19 | LogWriterFactory
20 | {
21 | private readonly ElmahLogLevels _logLevels;
22 | private ElmahLogWriterFactory(ElmahLogLevels logLevels)
23 | {
24 | _logLevels = logLevels;
25 | }
26 |
27 | public LogWriter Get(string name)
28 | {
29 | return new ElmahLogWriter(_logLevels);
30 | }
31 |
32 | public void Shutdown()
33 | {
34 |
35 | }
36 |
37 | public static void Use(ElmahLogLevels logLevels = null)
38 | {
39 | HostLogger.UseLogger(new ElmahHostLoggerConfigurator(logLevels));
40 | }
41 |
42 |
43 | [Serializable]
44 | public class ElmahHostLoggerConfigurator :
45 | HostLoggerConfigurator
46 | {
47 | private readonly ElmahLogLevels _logLevels;
48 | public ElmahHostLoggerConfigurator(ElmahLogLevels logLevels)
49 | {
50 | _logLevels = logLevels;
51 | }
52 |
53 | public LogWriterFactory CreateLogWriterFactory()
54 | {
55 | return new ElmahLogWriterFactory(_logLevels);
56 | }
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Builders/StopBuilder.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Builders
14 | {
15 | using System;
16 | using Hosts;
17 | using Runtime;
18 |
19 | public class StopBuilder :
20 | HostBuilder
21 | {
22 | readonly HostEnvironment _environment;
23 | readonly HostSettings _settings;
24 |
25 | public StopBuilder(HostEnvironment environment, HostSettings settings)
26 | {
27 | _environment = environment;
28 | _settings = settings;
29 | }
30 |
31 | public HostEnvironment Environment
32 | {
33 | get { return _environment; }
34 | }
35 |
36 | public HostSettings Settings
37 | {
38 | get { return _settings; }
39 | }
40 |
41 | public Host Build(ServiceBuilder serviceBuilder)
42 | {
43 | return new StopHost(_environment, _settings);
44 | }
45 |
46 | public void Match(Action callback)
47 | where T : class, HostBuilder
48 | {
49 | if (callback == null)
50 | throw new ArgumentNullException("callback");
51 |
52 | var self = this as T;
53 | if (self != null)
54 | {
55 | callback(self);
56 | }
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/src/Topshelf.Serilog/SerilogConfigurationExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using HostConfigurators;
16 | using Logging;
17 | using Serilog;
18 |
19 | public static class SerilogConfigurationExtensions
20 | {
21 | ///
22 | /// Configures Topshelf to use Serilog for logging, using the global instance to derive its loggers.
23 | ///
24 | public static void UseSerilog(this HostConfigurator configurator)
25 | {
26 | SerilogLogWriterFactory.Use(Log.Logger);
27 | }
28 |
29 | ///
30 | /// Configures Topshelf to use Serilog for logging, using the given to create loggers.
31 | ///
32 | public static void UseSerilog(this HostConfigurator configurator, LoggerConfiguration loggerConfiguration)
33 | {
34 | SerilogLogWriterFactory.Use(loggerConfiguration.CreateLogger());
35 | }
36 |
37 | ///
38 | /// Configures Topshelf to use Serilog for logging, using the given root logger to create loggers.
39 | ///
40 | public static void UseSerilog(this HostConfigurator configurator, ILogger rootLogger)
41 | {
42 | SerilogLogWriterFactory.Use(rootLogger);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/CommandLineSwitchConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using CommandLineParser;
17 | using Options;
18 |
19 | class CommandLineSwitchConfigurator :
20 | CommandLineConfigurator
21 | {
22 | readonly Action _callback;
23 | readonly string _name;
24 |
25 | public CommandLineSwitchConfigurator(string name, Action callback)
26 | {
27 | _name = name;
28 | _callback = callback;
29 | }
30 |
31 | public void Configure(ICommandLineElementParser parser)
32 | {
33 | parser.Add(from s in parser.Switch(_name)
34 | select (Option)new ServiceSwitchOption(s, _callback));
35 | }
36 |
37 | class ServiceSwitchOption :
38 | Option
39 | {
40 | readonly Action _callback;
41 | readonly bool _value;
42 |
43 | public ServiceSwitchOption(ISwitchElement element, Action callback)
44 | {
45 | _callback = callback;
46 | _value = element.Value;
47 | }
48 |
49 | public void ApplyTo(HostConfigurator configurator)
50 | {
51 | _callback(_value);
52 | }
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/src/Topshelf/Hosts/HelpHost.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Hosts
14 | {
15 | using System;
16 | using System.IO;
17 |
18 | ///
19 | /// Displays the Topshelf command line reference
20 | ///
21 | public class HelpHost :
22 | Host
23 | {
24 | readonly string _prefixText;
25 |
26 | public HelpHost(string prefixText)
27 | {
28 | _prefixText = prefixText;
29 | }
30 |
31 | public string PrefixText
32 | {
33 | get { return _prefixText; }
34 | }
35 |
36 | public TopshelfExitCode Run()
37 | {
38 | if (!string.IsNullOrEmpty(_prefixText))
39 | Console.WriteLine(_prefixText);
40 |
41 | const string helpText = "Topshelf.HelpText.txt";
42 |
43 | Stream stream = typeof(HelpHost).Assembly.GetManifestResourceStream(helpText);
44 | if (stream == null)
45 | {
46 | Console.WriteLine("Unable to load help text");
47 | return TopshelfExitCode.AbnormalExit;
48 | }
49 |
50 | using (TextReader reader = new StreamReader(stream))
51 | {
52 | string text = reader.ReadToEnd();
53 | Console.WriteLine(text);
54 | }
55 |
56 | return TopshelfExitCode.Ok;
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/Builders/CommandBuilder.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2014 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.Builders
14 | {
15 | using System;
16 | using Hosts;
17 | using Runtime;
18 |
19 |
20 | public class CommandBuilder :
21 | HostBuilder
22 | {
23 | readonly int _command;
24 | readonly HostEnvironment _environment;
25 | readonly HostSettings _settings;
26 |
27 | public CommandBuilder(HostBuilder builder, int command)
28 | {
29 | _command = command;
30 | _settings = builder.Settings;
31 | _environment = builder.Environment;
32 | }
33 |
34 | public HostEnvironment Environment
35 | {
36 | get { return _environment; }
37 | }
38 |
39 | public HostSettings Settings
40 | {
41 | get { return _settings; }
42 | }
43 |
44 | public Host Build(ServiceBuilder serviceBuilder)
45 | {
46 | return new CommandHost(_environment, _settings, _command);
47 | }
48 |
49 | public void Match(Action callback)
50 | where T : class, HostBuilder
51 | {
52 | if (callback == null)
53 | throw new ArgumentNullException(nameof(callback));
54 |
55 | var self = this as T;
56 | if (self != null)
57 | callback(self);
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/CommandLineDefinitionConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using CommandLineParser;
17 | using Options;
18 |
19 | class CommandLineDefinitionConfigurator :
20 | CommandLineConfigurator
21 | {
22 | readonly Action _callback;
23 | readonly string _name;
24 |
25 | public CommandLineDefinitionConfigurator(string name, Action callback)
26 | {
27 | _name = name;
28 | _callback = callback;
29 | }
30 |
31 | public void Configure(ICommandLineElementParser parser)
32 | {
33 | parser.Add(from s in parser.Definition(_name)
34 | select (Option)new ServiceDefinitionOption(s, _callback));
35 | }
36 |
37 | class ServiceDefinitionOption :
38 | Option
39 | {
40 | readonly Action _callback;
41 | readonly string _value;
42 |
43 | public ServiceDefinitionOption(IDefinitionElement element, Action callback)
44 | {
45 | _callback = callback;
46 | _value = element.Value;
47 | }
48 |
49 | public void ApplyTo(HostConfigurator configurator)
50 | {
51 | _callback(_value);
52 | }
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/HostConfigurators/RunAsUserHostConfigurator.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2013 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.HostConfigurators
14 | {
15 | using System;
16 | using System.Collections.Generic;
17 | using System.ServiceProcess;
18 | using Builders;
19 | using Configurators;
20 |
21 |
22 | public class RunAsUserHostConfigurator :
23 | HostBuilderConfigurator
24 | {
25 | public RunAsUserHostConfigurator(string username, string password)
26 | {
27 | Username = username;
28 | Password = password;
29 | }
30 |
31 | public string Password { get; private set; }
32 | public string Username { get; private set; }
33 |
34 | public HostBuilder Configure(HostBuilder builder)
35 | {
36 | if (builder == null)
37 | throw new ArgumentNullException("builder");
38 |
39 | builder.Match(x => x.RunAs(Username, Password, ServiceAccount.User));
40 |
41 | return builder;
42 | }
43 |
44 | public IEnumerable Validate()
45 | {
46 | if (string.IsNullOrEmpty(Username))
47 | yield return this.Failure("Username", "must be specified for a User account type");
48 | if (Password == null)
49 | yield return this.Failure("Password", "must be specified for a User account type");
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/CommandLineParser/ArgumentElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.CommandLineParser
14 | {
15 | class ArgumentElement :
16 | IArgumentElement
17 | {
18 | public ArgumentElement(string id)
19 | {
20 | Id = id;
21 | }
22 |
23 | public string Id { get; }
24 |
25 | public override string ToString()
26 | {
27 | return "ARGUMENT: " + Id;
28 | }
29 |
30 | public bool Equals(ArgumentElement other)
31 | {
32 | if (ReferenceEquals(null, other))
33 | return false;
34 | if (ReferenceEquals(this, other))
35 | return true;
36 | return Equals(other.Id, Id);
37 | }
38 |
39 | public override bool Equals(object obj)
40 | {
41 | if (ReferenceEquals(null, obj))
42 | return false;
43 | if (ReferenceEquals(this, obj))
44 | return true;
45 | if (obj.GetType() != typeof(ArgumentElement))
46 | return false;
47 | return Equals((ArgumentElement)obj);
48 | }
49 |
50 | public override int GetHashCode()
51 | {
52 | return Id?.GetHashCode() ?? 0;
53 | }
54 |
55 | public static ICommandLineElement New(string id)
56 | {
57 | return new ArgumentElement(id);
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/src/Topshelf/Configuration/CommandLineParser/TokenElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf.CommandLineParser
14 | {
15 | class TokenElement :
16 | ITokenElement
17 | {
18 | public TokenElement(string token)
19 | {
20 | Token = token;
21 | }
22 |
23 | public string Token { get; }
24 |
25 | public override string ToString()
26 | {
27 | return "TOKEN: " + Token;
28 | }
29 |
30 | public bool Equals(TokenElement other)
31 | {
32 | if (ReferenceEquals(null, other))
33 | return false;
34 | if (ReferenceEquals(this, other))
35 | return true;
36 | return Equals(other.Token, Token);
37 | }
38 |
39 | public override bool Equals(object obj)
40 | {
41 | if (ReferenceEquals(null, obj))
42 | return false;
43 | if (ReferenceEquals(this, obj))
44 | return true;
45 | if (obj.GetType() != typeof(TokenElement))
46 | return false;
47 | return Equals((TokenElement)obj);
48 | }
49 |
50 | public override int GetHashCode()
51 | {
52 | return Token?.GetHashCode() ?? 0;
53 | }
54 |
55 | public static ICommandLineElement New(string token)
56 | {
57 | return new TokenElement(token);
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/doc/source/configuration/logging.rst:
--------------------------------------------------------------------------------
1 | Logging Integration with Topshelf
2 | =================================
3 |
4 | By default, Topshelf uses a TraceSource for logging. This is part of the .NET framework, and thus does not introduce any additional dependencies. However, many applications use more advanced logging libraries, such as Logary or NLog. To support this, an extensible logging interface is used by Topshelf.
5 |
6 | Logary integration
7 | ------------------
8 |
9 | To ship logs with Logary, use the Logary.Adapters.Topshelf nuget. Once you've added this nuget to your project, you can configure Topshelf to use it via the configuration builder:
10 |
11 | .. sourcecode:: csharp
12 |
13 | using (var logary = ...Result)
14 | HostFactory.New(x =>
15 | {
16 | x.UseLogary(logary);
17 | });
18 |
19 | This makes it possible to get your logs off your node, so that you avoid running out of disk space and can log to modern log tagrets, such as ElasticSearch and InfluxDB.
20 |
21 | For more information, see the Logary README at https://github.com/logary/logary.
22 |
23 | log4net Integration
24 | -------------------
25 |
26 | To enable logging via log4net, the Topshelf.Log4Net NuGet package is available. Once added to your project, configure Topshelf to use log4net via the configuration:
27 |
28 | .. sourcecode:: csharp
29 |
30 | HostFactory.New(x =>
31 | {
32 | x.UseLog4Net();
33 | });
34 |
35 | This will change the ``HostLogger`` to use log4net. There is an overload that allows a configuration file to be specified. If given, the filename will be resolved to the ApplicationBase folder and passed to log4net to configure the log appenders and levels.
36 |
37 |
38 | NLog Integration
39 | ----------------
40 |
41 | To enable logging via NLog, the Topshelf.NLog NuGet package is available. Once added to your project, configure Topshelf to use NLog via the configuration:
42 |
43 | .. sourcecode:: csharp
44 |
45 | HostFactory.New(x =>
46 | {
47 | x.UseNLog();
48 | });
49 |
50 | This will change the ``HostLogger`` to use NLog. An existing LogFactory can be passed as well, using an overload of the same method.
51 |
52 |
--------------------------------------------------------------------------------
/src/Topshelf.Supervise/SuperviseConfiguratorExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | // this file except in compliance with the License. You may obtain a copy of the
5 | // License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software distributed
10 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 | // specific language governing permissions and limitations under the License.
13 | namespace Topshelf
14 | {
15 | using System;
16 | using System.Linq;
17 | using Builders;
18 | using Configurators;
19 | using HostConfigurators;
20 | using Supervise;
21 |
22 | public static class SuperviseConfiguratorExtensions
23 | {
24 | ///
25 | /// Configure the host to supervise the service
26 | ///
27 | ///
28 | ///
29 | public static HostConfigurator Supervise(this HostConfigurator hostConfigurator,
30 | Action configureCallback)
31 | {
32 | var superviseConfigurator = new SuperviseServiceConfigurator();
33 |
34 | configureCallback(superviseConfigurator);
35 |
36 | hostConfigurator.UseServiceBuilder(x =>
37 | {
38 | ConfigurationResult configurationResult =
39 | ValidateConfigurationResult.CompileResults(superviseConfigurator.Validate());
40 | if (configurationResult.Results.Any())
41 | throw new HostConfigurationException("The service was not properly configured");
42 |
43 | ServiceBuilder serviceBuilder = superviseConfigurator.Build();
44 |
45 | return serviceBuilder;
46 | });
47 |
48 | return hostConfigurator;
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------