I'm new to this forum (so apologies if I've posted in the wrong place) and also VERY NEW to Chef. I've been all around the houses trying to get a clear example of how to install a Windows service.
Basically I want the Chef equivalent of "SC create"
The recipe I'm trying to use is this:
windows_package "RMS_EU" do
installer_type :msi
action :install
source "c:\Servies\V5.5\EUNTRouteManager\Routing.WindowsService.exe"
end
When I run this I get error saying theres a problem with msi.
I've tried multiple variants of this script and am finding getting clear information on how to install a simple service incredibly sparse.
So does anyone know where I've gone wrong? As I say when this works it should appear as a Windows service in the services list.
The files are already on the service in the path specified, and I've running Windows 2008 R2, with PowerShell v4.0 and the latest Chef client install.
Any and all help would be appreciate.
Thanks for your feedback
Regards
Scott
In your resource, you are using the windows_package resource. This resource is not used to install services, but install to install packages (like MSI's that use an install wizard). The windows_package resource will call msiexec.exe on the machine, or a custom installer if you so specify.
The is no native command to install a service from an executable, but there is a way to execute sc.exe in order to do the install:
You may also want to set the service to logon as a specific user:
And then make sure the service starts.
A Note of Caution! The first resource block has the action :run and will then run every time chef-client runs on the machine. This will fail if the service is already installed, so the code is best wrapped around an IF check, or to use not_ifs to see if the service already exists before executing the first code block.
An addition to Obliviams answer:
Here is an example how to start a normal .exe as service with nssm and checking if service exists (Service is nginx):
A few things to look at, first switch all your slashes around so it is
"c:/Servies/V5.5/EUNTRouteManager/Routing.WindowsService.exe"
. Ruby, and most programming languages, use backslashes as escape sequences to encode characters that you can't normally see, like\n
for newlines or\t
for tabs.Next is the package install, you are telling it the file is an MSI but it ends with
.exe
so this is unlikely. From your text I'm guessing you aren't actually trying to install package file but for the future you'll have to match the install type to one of the known types (MSI, NSIS, etc).Finally, to control a service you'll want to use the
service or windows_service
resources, but you still need to create it. Fortunately there is a hidden helper for this:I don't have a Windows machine to test that on, but I think it should work.