What is the "correct" way to use Chocolatey to install a Windows service?
Asked Answered
K

1

7

I'm looking for some guidance on how I should be packaging my TopShelf hosted Windows service for distribution via Chocolatey. Currently the .nuspec puts the .exe and all .dlls into the \tools folder, which means they end up installed to ProgramData\chocolatey\lib\our-service\tools. That just doesn't seem right. In fact it was not a problem until I noticed that the uninstall logs all sorts of errors. Which are all related to Chocolatey trying to back up the files but can't because they are in use because the service is running. The chocolateyuninstall.ps1 stops the service but it doesn't run till after the backup attempt.

The application itself uses ProgramData\MyCompany\MyApp for all data and logging. Should I be putting the binaries there as well? Or is Program Files more appropriate? If one of these locations is correct, is chocolateyinstall.ps1 the logical place to put the code to xcopy the binaries? Or (and i hope you say no) is this not even a valid use of Chocolatey? Meaning like, should I suck it up and create an MSI for Chocolatey to operate on?

Thanks

Kalie answered 29/1, 2016 at 23:27 Comment(0)
D
3

Currently the .nuspec puts the .exe and all .dlls into the \tools folder, which means they end up installed to ProgramData\chocolatey\lib\our-service\tools. That just doesn't seem right. In fact it was not a problem until I noticed that the uninstall logs all sorts of errors. Which are all related to Chocolatey trying to back up the files but can't because they are in use because the service is running. The chocolateyuninstall.ps1 stops the service but it doesn't run till after the backup attempt.

We are adding a chocolateyBeforeModify.ps1 script that will be run before upgrade/uninstall - https://github.com/chocolatey/choco/issues/268. That should be in 0.9.10 and will help make the workflow smoother.

Currently you must stop the service outside of Chocolatey prior to attempting to upgrade or uninstall.

Another thing to consider is that Chocolatey takes advantage of XDT (Xml Document Transformations), which means if you include an *.install.xdt file for an xml config, choco won't simply overwrite an existing file. That allows you to upgrade in a package folder without overwriting any user configuration. However, if you are copying the files off somewhere else, you need to figure this aspect out on your own.

The application itself uses ProgramData\MyCompany\MyApp for all data and logging. Should I be putting the binaries there as well? Or is Program Files more appropriate?

We don't yet have a recommended way of installing a service or setting up a website / web application. Both of these things we will be creating helpers for in the future, at which time we will recommend those avenues and have better recommendations about where things should go.

Update 20170324: We now have Install-ChocolateyWindowsService and other service related functions in the business edition of Chocolatey.

If one of these locations is correct, is chocolateyinstall.ps1 the logical place to put the code to xcopy the binaries?

The automation scripts are the logical place to perform any actions you need to take after the package bits are added.

Or (and i hope you say no) is this not even a valid use of Chocolatey? Meaning like, should I suck it up and create an MSI for Chocolatey to operate on?

Creating services and websites is definitely a valid use of Chocolatey. I recommend not to create an MSI unless you need to. It's quite an involved process and in most cases (like for internal applications), it feels like overkill.

Duda answered 30/1, 2016 at 14:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.