Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.
If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!
Getting windows service status into variable
-
I am working on using BuildMaster to handle automated deployments for some of our windows services. Everything seems fine except for one thing. For some services, we will have it deployed on multiple servers, but only have it running on certain ones. This is due to a mixture of redundency, server usage, etc. I can't seem to determine a manner in which I can get service startup type and/or current running status into a variable and act on it conditionally.
I can see a manner in which I could use PSEval to pull this off, but wanted to make sure I wasn't missing a simpler solution.
-
Great to hear!
Well, of course, you could store the information about which services are active in BuildMaster. I would imagine it's not something that changes very often, so perhaps this is OK?
One approach might be to make a server role called
hdars-service
and then add a variable to that role called$ActiveServer
with the server name. You would set a pipeline target to rundeploy-hdars
tohdards-service
role, and in that plan, just do aif $ServerName == $ActiveServer
to decide whether to start/stop service, or whatever.Otherwise, I think using powershell of some sort, whether
$PSEval
or a making an OtterSCript module with an output variable.
-
Sorry about the long delay in response.
Your answer was helpful as I had not realized that roles could contain variables in that way. It will help with some other stuff I was thinking about doing.
I did end up going with the powershell route as the some of our services do shuffle a bit. I think I have the script set up correctly, but when I execute the build step I get the following error:
Unhandled exception: System.Management.Automation.Runspaces.PSSnapInException: An error occurred while attempting to load the system Windows PowerShell snap-ins. Please contact Microsoft Customer Support Services. ---> System.Management.Automation.PSArgumentException: Unable to access Windows PowerShell PowerShellEngine registry information.
The agent is installed with the recommended user account. It's a Microsoft Server 2008 R2 server with service pack 1 and powershell 2. I couldn't find any information elsewhere on the site about how to resolve this. Help appreciated.
-
Error was related to how we had base install Windows Management Framework/Powershell installed. Updating to WMF/Powershell 4 resolved this error. Working through some mistakes in the scripting, but if I can get through it all without any more questions, I'll mark this post as answered.