Skip to content

Instantly share code, notes, and snippets.

@jbezak
Last active May 10, 2017 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbezak/eda4cc5864059b717e71beaec47db2d9 to your computer and use it in GitHub Desktop.
Save jbezak/eda4cc5864059b717e71beaec47db2d9 to your computer and use it in GitHub Desktop.
Combining TopShelf with Installer for InstallUtil.exe
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