Created
February 14, 2012 22:00
-
-
Save logicbomb/1830880 to your computer and use it in GitHub Desktop.
topshelf service install
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 System; | |
using System.IO; | |
using Lemur.Logging; | |
using log4net.Config; | |
using NConfig; | |
using Topshelf; | |
namespace Lemur.CommandHost | |
{ | |
public class Program : ILoggingSource | |
{ | |
private Program() | |
{ | |
} | |
public static void Main(string[] args) | |
{ | |
NConfigurator.UsingFile(@"Config\custom.config").SetAsSystemDefault(); | |
XmlConfigurator.Configure(new FileInfo(Path.Combine(Environment.CurrentDirectory, NConfigurator.Default.FileNames[0]))); | |
var logSource = new LogSource(); | |
// Report on configuration | |
logSource.Debug("Using configuration file: {0}", Path.Combine(Environment.CurrentDirectory, NConfigurator.Default.FileNames[0])); | |
logSource.Debug("Using connection string: {0}", System.Configuration.ConfigurationManager.ConnectionStrings["lemur"].ConnectionString); | |
try | |
{ | |
HostFactory.Run(x => | |
{ | |
logSource.Debug("HostFactory is running"); | |
x.Service<CommandHost>(s => | |
{ | |
try | |
{ | |
logSource.Debug("HostConfigurator is running"); | |
s.ConstructUsing(commandHost => | |
{ | |
logSource.Debug("Construct using new CommandHost()"); | |
return new CommandHost(); | |
}); | |
logSource.Debug("ConstructUsing executed"); | |
s.WhenStarted(commandHost => | |
{ | |
logSource.Debug("Calling commandHost.Start()"); | |
commandHost.Start(); | |
}); | |
logSource.Debug("WhenStarted executed"); | |
s.WhenStopped(commandHost => | |
{ | |
logSource.Debug("Calling commandHost.Stop()"); | |
commandHost.Stop(); | |
logSource.Debug("Calling commandHost.Stop()"); | |
}); | |
logSource.Debug("WhenStopped executed"); | |
} | |
catch (Exception e) | |
{ | |
logSource.Error("An error of type {0} occurred while running HostFactory.Service() command host {1}, {2}", e.GetType().Name, e.Message, e.StackTrace); | |
throw; | |
} | |
}); | |
x.SetDescription("Processes commands issued by the Lemur Web Application"); | |
x.SetDisplayName("Lemur Command Host"); | |
x.SetServiceName("LemurCommandHost"); | |
x.RunAsLocalSystem(); | |
x.BeforeInstall(() => logSource.Debug("Installing Lemur Command Host Service")); | |
x.BeforeUninstall(() => logSource.Debug("UnInstalling Lemur Command Host Service")); | |
x.AfterInstall(() => logSource.Debug("Installed Lemur Command Host Service")); | |
x.AfterUninstall(() => logSource.Debug("Uninstalled Lemur Command Host Service")); | |
x.BeforeStartingServices(() => logSource.Debug("Starting command host")); | |
x.AfterStartingServices(() => logSource.Debug("Started command host")); | |
}); | |
} | |
catch (Exception e) | |
{ | |
logSource.Error(e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Log output (including debug info from TopShelf)