Created
October 4, 2013 08:57
-
-
Save metavige/6823029 to your computer and use it in GitHub Desktop.
TopShelf Startup
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
// Start setup running service | |
HostFactory.New(x => | |
{ | |
x.Service<DeployMonitorService>(c => | |
{ | |
c.ConstructUsing(s => ServiceLocator.Current.GetInstance<DeployMonitorService>()); | |
c.WhenStarted(s => s.Start()); | |
c.WhenStopped(s => s.Stop()); | |
c.WhenPaused(s => s.Pause()); | |
c.WhenContinued(s => s.Resume()); | |
}); | |
x.RunAsLocalSystem(); // 設定成 Local System 才能寫入 Log 檔案 | |
x.SetDescription("Window Service Description"); | |
x.SetServiceName("WindowServiceName"); // Service 名稱不可以有空格 | |
x.SetDisplayName("Window Service Display Title"); // 顯示名稱才可以有空格 | |
x.StartAutomaticallyDelayed(); | |
// x.DependsOnIis(); | |
x.EnablePauseAndContinue(); | |
x.EnableShutdown(); | |
x.EnableServiceRecovery(rc => | |
{ | |
rc.RestartService(1); // restart the service after 1 minute | |
rc.SetResetPeriod(1); | |
// rc.SetResetPeriod(1); // set the reset interval to one day | |
}); | |
//x.UseLog4Net(); | |
}).Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment