Created
August 21, 2017 23:54
-
-
Save PaulNichols/a64da996fd09d4a6dec3fb6c7582bc6a to your computer and use it in GitHub Desktop.
Topshelf Windows Service configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Topshelf; | |
internal static class ConfigureService | |
{ | |
internal static void Configure(<ServiceType> serviceName) | |
{ | |
HostFactory.Run(configure => | |
{ | |
configure.UseSerilog(); | |
configure.Service<ServiceType>(x => | |
{ | |
x.ConstructUsing(name => serviceName); | |
x.WhenStarted(tc => tc.Start()); | |
x.WhenStopped(tc => tc.Stop()); | |
}); | |
configure.RunAsLocalSystem(); | |
configure.SetServiceName("Site Management Service"); | |
configure.SetDisplayName("Site Management Service"); | |
configure.SetDescription("Site Management Service by Mexia"); | |
configure.EnableServiceRecovery(r => | |
{ | |
r.RestartService(1); | |
r.OnCrashOnly(); | |
}); | |
configure.EnableServiceRecovery(r => | |
{ | |
r.OnCrashOnly(); | |
r.RestartService(1); //first | |
r.RestartService(1); //second | |
r.RestartService(1); //subsequents | |
r.SetResetPeriod(0); | |
}); | |
string siteId = ""; | |
configure.AddCommandLineDefinition("SiteId", s => siteId = s); | |
configure.BeforeInstall(() => | |
{ | |
}); | |
configure.AfterInstall(() => | |
{ | |
}); | |
configure.StartAutomatically(); | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment