Last active
May 10, 2017 17:14
-
-
Save jbezak/eda4cc5864059b717e71beaec47db2d9 to your computer and use it in GitHub Desktop.
Combining TopShelf with Installer for InstallUtil.exe
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
namespace FsharpService | |
open System.ComponentModel | |
open System.Configuration.Install | |
open System.Diagnostics | |
[<RunInstaller(true)>] | |
type public FSharpServiceInstaller() = | |
inherit Installer() | |
let assemblyIdentifier = "FsharpService.exe" | |
let runHiddenProcess fileName arguments = | |
let startInfo = new ProcessStartInfo(fileName) | |
startInfo.WindowStyle <- ProcessWindowStyle.Hidden | |
startInfo.Arguments <- arguments | |
use hiddenProcess = Process.Start(startInfo) | |
hiddenProcess.WaitForExit() | |
override __.Install(stateSaver : System.Collections.IDictionary) = | |
let assemblyPath = __.Context.Parameters.["assemblypath"] | |
stateSaver.Add(assemblyIdentifier, assemblyPath) | |
runHiddenProcess assemblyPath "install" | |
base.Install(stateSaver) | |
override __.Uninstall(savedState : System.Collections.IDictionary) = | |
let assemblyPath = savedState.[assemblyIdentifier].ToString() | |
runHiddenProcess assemblyPath "uninstall" | |
base.Uninstall(savedState) | |
type FsharpService() = | |
member __.Start() = () | |
member __.Stop() = () | |
module Main = | |
open Topshelf | |
let service = new FsharpService() | |
Service.Default | |
|> service_name "FsharpService" | |
|> display_name "FsharpService" | |
|> description "FsharpService description" | |
|> with_start (fun _ -> service.Start()) | |
|> with_stop (fun _ -> service.Stop()) | |
|> run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment