Not sure how best to do this

We have a TopShelf Windows Service which I need to deploy to the same server with 2 instances, I have in the Program.cs code to read the ServiceName from the app.config file - all good so far.

I have 2 separate projects within Octopus deploy which share the same nuget package, and If I set the ServiceName in the variables then I was hoping this would work.

Coming to the conclusion I may need to change the name of the service.exe after its been deployed along with the confif file so I would have something like the following:-

  • 2 projects within OD which both deploy the same nuget package

  • Have a step which renames each of the service.exes to be say ServiceA.exe and ServiceB.exe as well as renaming both the Service.exe.config files.

  • Install the Service and then that should work

Unfortunately I cant see how to install the package, rename the service exe and then install the package using OD steps, the post deployment script doesn’t output the folder I have deployed the nuget package to.

Any ideas on how to achieve this?

Nuget packaged deployed

Hey there

There isn’t going to be a super easy way to do this. Our script to configure services uses sc.exe and the params set the service name etc. Topshelf does a lot of the same stuff (as you know) and if the names don’t match then the service won’t start.

However, topshelf gives you a command line param to register the service with an instance name.

Soooo, you’re probably best off writing your own powershell script as that will register your service through the topshelf commands and takes in a variable. You could uninstall / reinstall the service for new versions rather than re configuring it like we do with sc.exe.

Does that help you ?



I cant seem to get the -instance to work

I have this:-
sc.exe create MyServiceName binpath= $exePath -instance=“A” displayname= “MyService(Instance: A)”

What if you did (and I’m going from memory here) my service.exe install -whateverthetopshelfinstanceparamis myinstance

And ignore sc.exe totally.

What’s the best way to handle new versions - ie uninstalling the old service and reinstalling the new one within powershell.

net stop servicename

sc delete servicename

something like that? - what about if it fails etc?

I’d forget all about sc.exe and use the topshelf commands, it will handle all your instance stuff.

But yes, probably uninstall and reinstall.

How do I get the path to the previously installed package these both return an empty string:-

$previous = $OctopusParameters[‘Octopus.Tentacle.PreviousInstallation.CustomInstallationDirectory’]
Write-Host “previous = $($previous)”

$previousPath = $OctopusParameters[‘Octopus.Tentacle.PreviousInstallation.OriginalInstalledPath’]
Write-Host “previousPath = $($previousPath)”

I see on Twitter you got this working, all good now ?

Yeah thanks for your help - I’ll blog my findings and how I got it working