Last active
July 3, 2018 18:09
-
-
Save seankearon/a0ac3b310cdf9ff74284 to your computer and use it in GitHub Desktop.
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
Deployment steps for this blog post: | |
http://kearon.blogspot.co.uk/2015/01/installing-service-using-topshelf-with.html |
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
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 | |
} |
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
$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 |
this was a great help thanks, i did find that PathName is not always quoted, in which case i modifed Get-ServiceExePath to be like this
function Get-ServiceExePath ($name)
{
$service = Get-WmiObject win32_service | ?{$_.Name -eq $name}
if($service)
{
$exePath = $service.PathName
if($exePath.startsWith('"'))
{
$exePath = $exePath.split('"')[1]
}
$exePath
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the escaping in the post-deployment script might be missing? "`" instead of '' worked for me.