Reputation: 3447
Ok, this is what I want to do -
We have a windows service and we want to automate deployment of this service to the test environments after every successful CI build - for this we thought of the following approach -
However, currently I am facing problems with the starting and stopping of the windows service.
This is the MSBuild snippet -
<!-- TODO: do this using Powershell instead of normal commandline so that it can be executed on remote machines as well -->
<Exec Command="Net Stop CreditProcessing" />
<!-- Exec Command="$(PowerShellExe) -NoProfile -Noninteractive -command "&{ Stop-Service CreditProcessing }"" /-->
<!-- TODO: The destination needs to come from the env variable or rsp file? -->
<Copy
SourceFiles="@(WindowsServiceFilesToDeploy)"
DestinationFiles="@(WindowsServiceFilesToDeploy->'D:\WindowsServices\Credit Processing Service%(RecursiveDir)%(Filename)%(Extension)')" />
<Exec Command="Net Start CreditProcessing" />
<!--Exec Command="$(PowerShellExe) -NoProfile -Noninteractive -command Start-Service CreditProcessing" /-->
This I tried with both direct command line commands as well as powershell commands.
A) This is the problem I face when I try to run this build with normal commands - the service takes some time to start/stop and the build doesn't wait long enough and reports an error and stops
"... service could not be started". "Service did not report an error"
or sometimes when stopping
"The service could not be controlled in its present state."
whereas if we immediately check the services it will be in "Starting" stage and soon it will go to "Start" stage. Any way to make the build be a little more patient? The command doesn't do this if run directly from command prompt.
B) This is the problem we face if I use the above powershell commands (currently commented in the snippet) -
It just opens the powershell prompt in the build log and then just does nothing
Can you help avoid these problems (at least one of these)? I think the powershell route is more recommended if it works fine, but I'm open to suggestions.
A couple of other questions -
We want to deploy the service (and hence stop and restart) on a remote machine (other than where this CI build is happening) - anyway this can be done?
Is there a way to add a check whether the service is already running and stop only if it is running? If it is stopped and we try to stop again, it will give "Service not started" error
Upvotes: 2
Views: 980
Reputation: 4002
Your command to launch is of this form:
path\to\powershell.exe
-arg1 -arg2
The newline means that PowerShell never receives the arguments, so doesn't know it has to execute a Start-Service
command, and doesn't know you don't want it to be interactive. It's probably just waiting for you to tell it what to do.
Check your $(PowerShell) variable, as it probably has a newline at the end.
Upvotes: 1
Reputation: 26150
why not use sc.exe which has native remote capabilities ?
Upvotes: 1