diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-20 21:04:14 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-20 21:04:14 -0400 |
| commit | 2e511fba839e86d9393e5eeb10795f1b0aed7ce0 (patch) | |
| tree | d82481b8352ae2f088cbe902cc7fc222b8b0a0ed /MediaBrowser.ServerApplication/BackgroundServiceInstaller.cs | |
| parent | b5615cb233923f8424a40af009101a901f30f591 (diff) | |
support run as service
Diffstat (limited to 'MediaBrowser.ServerApplication/BackgroundServiceInstaller.cs')
| -rw-r--r-- | MediaBrowser.ServerApplication/BackgroundServiceInstaller.cs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/MediaBrowser.ServerApplication/BackgroundServiceInstaller.cs b/MediaBrowser.ServerApplication/BackgroundServiceInstaller.cs new file mode 100644 index 000000000..435d2f181 --- /dev/null +++ b/MediaBrowser.ServerApplication/BackgroundServiceInstaller.cs @@ -0,0 +1,60 @@ +using System.Collections; +using System.ComponentModel; +using System.ServiceProcess; + +namespace MediaBrowser.ServerApplication +{ + [RunInstaller(true)] + public class BackgroundServiceInstaller : System.Configuration.Install.Installer + { + public BackgroundServiceInstaller() + { + var process = new ServiceProcessInstaller + { + Account = ServiceAccount.LocalSystem + }; + + var serviceAdmin = new ServiceInstaller + { + StartType = ServiceStartMode.Manual, + ServiceName = BackgroundService.Name, + DisplayName = BackgroundService.DisplayName, + DelayedAutoStart = true, + Description = "The windows background service for Media Browser Server." + }; + + // Microsoft didn't add the ability to add a + // description for the services we are going to install + // To work around this we'll have to add the + // information directly to the registry but I'll leave + // this exercise for later. + + // now just add the installers that we created to our + // parents container, the documentation + // states that there is not any order that you need to + // worry about here but I'll still + // go ahead and add them in the order that makes sense. + Installers.Add(process); + Installers.Add(serviceAdmin); + } + + protected override void OnBeforeInstall(IDictionary savedState) + { + Context.Parameters["assemblypath"] = "\"" + + Context.Parameters["assemblypath"] + "\" " + GetStartArgs(); + base.OnBeforeInstall(savedState); + } + + protected override void OnBeforeUninstall(IDictionary savedState) + { + Context.Parameters["assemblypath"] = "\"" + + Context.Parameters["assemblypath"] + "\" " + GetStartArgs(); + base.OnBeforeUninstall(savedState); + } + + private string GetStartArgs() + { + return "-service"; + } + } +} |
