$exe = $OctopusParameters['Octopus.Action.Package.CustomInstallationDirectory'] + '\' + $OctopusParameters['ExeName']
$serviceName = $OctopusParameters['Topshelf.ServiceName']
write-host "Installing service: " + $serviceName
write-host "Executable: " + $exe
& $exe install --autostart
Start-Service $serviceName
write-host "Service installed: " + $serviceName
function Get-ServiceExePath ($name)
{
$service = Get-WmiObject win32_service | ?{$_.Name -eq $name}
$path = $service | select @{Name="Path"; Expression={$_.PathName.split('"')[1]}}
$path.Path
}
$ServiceName = $OctopusParameters['MyServiceName']
$ExePath = Get-ServiceExePath $ServiceName
Write-Host "Removing service: " + $ServiceName
if ($ExePath)
{
Write-Host "Service executable: " + $ExePath
& $ExePath uninstall
Write-Host "Service removed."
}
else
{
Write-Host "Service not found: " + $ServiceName
}
Deployment steps for this blog post:
http://kearon.blogspot.co.uk/2015/01/installing-service-using-topshelf-with.html