Dejulia489 / WindowsServiceManager

https://marketplace.visualstudio.com/items?itemName=MDSolutions.WindowsServiceManagerWindowsServiceManager
MIT License
11 stars 9 forks source link

Cannot Stop/Start Windows Service #26

Closed dhabierre closed 4 years ago

dhabierre commented 4 years ago

Hi,

I am using this task to deploy 2 Windows services. Here the configuration:

image

=> All services are running using the same domain account (administrator account)

Deployment step (the 2 services have Stop Process option on):

image

Deployment output (for the 2 services):

Service responded with [2]. See https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/startservice-method-in-class-win32-service for details.

[2] => The user did not have the necessary access.

No more information in the EventViewer.

The step cannot neither stop nor start the services.

2020-03-04T17:05:40.7943097Z ##[debug]Evaluating condition for step: 'Deploy Windows Service (GenericServices)'
2020-03-04T17:05:40.7943814Z ##[debug]Evaluating: succeeded()
2020-03-04T17:05:40.7943950Z ##[debug]Evaluating succeeded:
2020-03-04T17:05:40.7944216Z ##[debug]=> True
2020-03-04T17:05:40.7944538Z ##[debug]Result: True
2020-03-04T17:05:40.7944841Z ##[section]Starting: Deploy Windows Service (GenericServices)
2020-03-04T17:05:40.8352778Z ==============================================================================
2020-03-04T17:05:40.8352896Z Task         : Windows Service Manager
2020-03-04T17:05:40.8352979Z Description  : Deploys a Windows Service to an Agent or a Deployment Group Target using WinRM.
2020-03-04T17:05:40.8353048Z Version      : 4.1.23
2020-03-04T17:05:40.8353802Z Author       : MDSolutions
2020-03-04T17:05:40.8353939Z Help         : [More Information](https://github.com/Dejulia489/WindowsServiceManager)
2020-03-04T17:05:40.8354018Z ==============================================================================
2020-03-04T17:05:41.7526166Z ##[debug]VstsTaskSdk 0.11.0 commit 7ff27a3e0bdd6f7b06690ae5f5b63cb84d0f23f4
2020-03-04T17:05:41.9427717Z ##[debug]INPUT_DEPLOYMENTTYPE: 'DeploymentGroup'
2020-03-04T17:05:41.9767517Z ##[debug]INPUT_SERVICENAME: 'Car.Game.WindowsService.GenericServices'
2020-03-04T17:05:41.9774199Z ##[debug]INPUT_ARTIFACTPATH: 'C:\agents\agent-deployment\_work\r2\a\_CI - Game\WindowsServices\Car.Game.WindowsService.GenericServices'
2020-03-04T17:05:41.9829476Z ##[debug]INPUT_TIMEOUT: '60'
2020-03-04T17:05:41.9921884Z ##[debug]INPUT_CLEANINSTALL: 'false'
2020-03-04T17:05:41.9979641Z ##[debug] Converted to bool: False
2020-03-04T17:05:42.0115368Z ##[debug]INPUT_STOPPROCESS: 'true'
2020-03-04T17:05:42.0219179Z ##[debug] Converted to bool: True
2020-03-04T17:05:42.0243038Z ##[debug]INPUT_INSTALLSERVICE: 'false'
2020-03-04T17:05:42.0424849Z ##[debug] Converted to bool: False
2020-03-04T17:05:42.0664566Z ##[debug]Entering C:\agents\agent-deployment\_work\_tasks\WindowsServiceManager_7dad075d-a817-45ac-baab-4c1376d2885e\4.1.23\DeployWindowsService.ps1.
2020-03-04T17:05:42.0745117Z [XXX]: Attempting to locate [Car.Game.WindowsService.GenericServices]
2020-03-04T17:05:42.6066145Z [XXX]: Identified [Car.Game.WindowsService.GenericServices] installation directory [D:\XXX\SERVICES\Car.Game.WindowsService.GenericServices]
2020-03-04T17:05:42.6076184Z [XXX]: Copying [C:\agents\agent-deployment\_work\r2\a\_CI - Game\WindowsServices\Car.Game.WindowsService.GenericServices] to [D:\XXX\SERVICES\Car.Game.WindowsService.GenericServices]
2020-03-04T17:05:43.0320639Z [XXX]: Starting [Car.Game.WindowsService.GenericServices]
2020-03-04T17:05:43.3356684Z ##[debug]Caught exception from task script.
2020-03-04T17:05:43.3393919Z ##[debug]Error record:
2020-03-04T17:05:43.4016064Z ##[debug]Start-WindowsService : [XXX]: Service responded with [2]. See https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/startservice-method-in-class-win32-service for details.
2020-03-04T17:05:43.4029914Z ##[debug]At C:\agents\agent-deployment\_work\_tasks\WindowsServiceManager_7dad075d-a817-45ac-baab-4c1376d2885e\4.1.23\DeployWindowsService.ps1:241 char:9
2020-03-04T17:05:43.4046659Z ##[debug]+         Start-WindowsService -ServiceName $ServiceName
2020-03-04T17:05:43.4060767Z ##[debug]+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-03-04T17:05:43.4078949Z ##[debug]    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
2020-03-04T17:05:43.4094173Z ##[debug]    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Start-WindowsService
2020-03-04T17:05:43.4108994Z ##[debug] 
2020-03-04T17:05:43.4133206Z ##[debug]Script stack trace:
2020-03-04T17:05:43.4176712Z ##[debug]at Start-WindowsService, C:\agents\agent-deployment\_work\_tasks\WindowsServiceManager_7dad075d-a817-45ac-baab-4c1376d2885e\4.1.23\DeployWindowsService.ps1: line 97
2020-03-04T17:05:43.4192425Z ##[debug]at <ScriptBlock>, C:\agents\agent-deployment\_work\_tasks\WindowsServiceManager_7dad075d-a817-45ac-baab-4c1376d2885e\4.1.23\DeployWindowsService.ps1: line 241
2020-03-04T17:05:43.4206985Z ##[debug]at <ScriptBlock>, C:\agents\agent-deployment\_work\_tasks\WindowsServiceManager_7dad075d-a817-45ac-baab-4c1376d2885e\4.1.23\DeployWindowsService.ps1: line 257
2020-03-04T17:05:43.4221753Z ##[debug]at <ScriptBlock>, <No file>: line 1
2020-03-04T17:05:43.4236332Z ##[debug]at <ScriptBlock>, <No file>: line 22
2020-03-04T17:05:43.4250865Z ##[debug]at <ScriptBlock>, <No file>: line 18
2020-03-04T17:05:43.4266271Z ##[debug]at <ScriptBlock>, <No file>: line 1
2020-03-04T17:05:43.4290968Z ##[debug]Exception:
2020-03-04T17:05:43.4345760Z ##[debug]Microsoft.PowerShell.Commands.WriteErrorException: [XXX]: Service responded with [2]. See https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/startservice-method-in-class-win32-service for details.
2020-03-04T17:05:43.4720778Z ##[error][XXX]: Service responded with [2]. See https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/startservice-method-in-class-win32-service for details.
2020-03-04T17:05:43.4729493Z ##[debug]Processed: ##vso[task.logissue type=error][XXX%5D: Service responded with [2%5D. See https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/startservice-method-in-class-win32-service for details.
2020-03-04T17:05:43.4734181Z ##[debug]Processed: ##vso[task.complete result=Failed]
2020-03-04T17:05:43.5168132Z ##[section]Finishing: Deploy Windows Service (GenericServices)

Any idea? Thanks!

Dejulia489 commented 4 years ago

Can you provide a screenshot of the computers administrators role.

dhabierre commented 4 years ago

Hi @Dejulia489

Here the screenshot:

image

Information about the OS version:

image

dhabierre commented 4 years ago

This morning, I have this output:

[debug]VstsTaskSdk 0.11.0 commit 7ff27a3e0bdd6f7b06690ae5f5b63cb84d0f23f4
[debug]INPUT_DEPLOYMENTTYPE: 'DeploymentGroup'
[debug]INPUT_SERVICENAME: 'Car.Game.WindowsService.GenericServices'
[debug]INPUT_ARTIFACTPATH: 'C:\agents\agent-deployment\_work\r2\a\_CI - Game\WindowsServices\Car.Game.WindowsService.GenericServices'
[debug]INPUT_TIMEOUT: '60'
[debug]INPUT_CLEANINSTALL: 'false'
[debug] Converted to bool: False
[debug]INPUT_STOPPROCESS: 'true'
[debug] Converted to bool: True
[debug]INPUT_INSTALLSERVICE: 'false'
[debug] Converted to bool: False
[debug]Entering C:\agents\agent-deployment\_work\_tasks\WindowsServiceManager_7dad075d-a817-45ac-baab-4c1376d2885e\4.1.23\DeployWindowsService.ps1.
[XXX]: Attempting to locate [Car.Game.WindowsService.GenericServices]
[XXX]: Stopping [Car.Game.WindowsService.GenericServices]
[debug][XXX]: [Car.Game.WindowsService.GenericServices] did not respond within [60] seconds, stopping process.
[debug][XXX]: [Car.Game.WindowsService.GenericServices] did not respond within [60] seconds, stopping process.
[debug][XXX]: [Car.Game.WindowsService.GenericServices] did not respond within [60] seconds, stopping process.
[debug][XXX]: [Car.Game.WindowsService.GenericServices] did not respond within [60] seconds, stopping process.
[debug][XXX]: [Car.Game.WindowsService.GenericServices] did not respond within [60] seconds, stopping process.
[debug][XXX]: [Car.Game.WindowsService.GenericServices] did not respond within [60] seconds, stopping process.
[debug][XXX]: [Car.Game.WindowsService.GenericServices] did not respond within [60] seconds, stopping process.
[debug][XXX]: [Car.Game.WindowsService.GenericServices] did not respond within [60] seconds, stopping process.
[debug][XXX]: [Car.Game.WindowsService.GenericServices] did not respond within [60] seconds, stopping process.
[debug][XXX]: [Car.Game.WindowsService.GenericServices] did not respond within [60] seconds, stopping process.
...
dhabierre commented 4 years ago

This issue can be closed.

I have exactly the same issue using Command Line task:

image

Result:

2020-03-05T10:42:03.8486506Z System error 5 has occurred.
2020-03-05T10:42:03.8486643Z 
2020-03-05T10:42:03.8486711Z Access is denied.
2020-03-05T10:42:03.8486756Z 
2020-03-05T10:42:03.8511486Z ##[debug]Exit code: 2
2020-03-05T10:42:03.8512195Z ##[debug]Leaving Invoke-VstsTool.
2020-03-05T10:42:03.9190587Z ##[error]Cmd.exe exited with code '2'.

=> right problem.

Thanks!

dhabierre commented 4 years ago

My 2 cents.

Azure DevOps agent is now running under NT AUTHORITY\SYSTEM account (default one when installing it).

Then, release pipeline:

First, try to stop the service (=> Continue on error):

image

Finally, restart the service (raise error on failure):

image

Dejulia489 commented 4 years ago

You resolved the permission issue by update the agent service account? Have you tried using the Windows Manager Extension since the update?

dhabierre commented 4 years ago

Test 1

AzDevOps agent: NT AUTHORITY\SYSTEM (default account when installing the agent) Windows Services: HO\FRGXXX account (admin) Windows Manager extension => access denied

Test 2

AzDevOps agent: HO\FRGXXX Windows Services: HO\FRGXXX Windows Manager extension => access denied

Test 3 (same configuration as Test 1)

AzDevOps agent: NT AUTHORITY\SYSTEM Windows Services: HO\FRGXXX Command Line Script (net stop|start ServiceName) => OK

I've tried again with Windows Manager extension and now it is Ok !? Perhaps an Ops has performed some actions on the server / rights...

Dejulia489 commented 4 years ago

Closing this ticket.