jabbera / my-vsts-tasks

20 stars 18 forks source link

Stop Windows Service v8.0.0 - Disabled Startup does not stop process #37

Closed Sigman32 closed 6 years ago

Sigman32 commented 6 years ago

I tried setting service to disabled startup type, and stopping it, but service was not stopped, and next release step failed.

Here are task logs:

2018-07-03T08:46:48.1286460Z ##[debug]Evaluating condition for step: 'Stop Windows Service: MyService'
2018-07-03T08:46:48.1286460Z ##[debug]Evaluating: succeeded()
2018-07-03T08:46:48.1286460Z ##[debug]Evaluating succeeded:
2018-07-03T08:46:48.1286460Z ##[debug]=> (Boolean) True
2018-07-03T08:46:48.1296460Z ##[debug]Expanded: True
2018-07-03T08:46:48.1296460Z ##[debug]Result: True
2018-07-03T08:46:48.1296460Z ##[section]Starting: Stop Windows Service: MyService
2018-07-03T08:46:48.1306460Z ==============================================================================
2018-07-03T08:46:48.1316460Z Task         : Stop Windows Service
2018-07-03T08:46:48.1316460Z Description  : Stop a windows service.
2018-07-03T08:46:48.1316460Z Version      : 8.0.0
2018-07-03T08:46:48.1316460Z Author       : Michael Barry
2018-07-03T08:46:48.1316460Z Help         : [More Information](https://github.com/jabbera/my-vsts-tasks)
2018-07-03T08:46:48.1326460Z ==============================================================================
2018-07-03T08:46:48.9586460Z ##[debug]VstsTaskSdk 0.6.4 commit a074a158dbd70b5a72d1295ee42684c30a262b19
2018-07-03T08:46:49.0436460Z ##[debug]Entering C:\vstsagent\A1\_work\_tasks\StopWindowsService_601cd43e-b65d-49b7-b118-091333bd5b9f\8.0.0\StopWindowsService.ps1.
2018-07-03T08:46:49.0736460Z ##[debug]Env:INPUT_SERVICENAMES: 'MyService'
2018-07-03T08:46:49.0766460Z ##[debug]Env:INPUT_INSTANCENAME (empty)
2018-07-03T08:46:49.0876460Z ##[debug]Env:INPUT_STARTUPTYPE: 'Disabled'
2018-07-03T08:46:49.0906460Z ##[debug]Env:INPUT_WAITTIMEOUTINSECONDS: '120'
2018-07-03T08:46:49.0926460Z ##[debug]Env:INPUT_KILLIFTIMEDOUT: 'true'
2018-07-03T08:46:49.0956460Z ##[debug]Env:INPUT_DEPLOYMENTGROUP: 'true'
2018-07-03T08:46:49.0996460Z ##[debug] Converted to bool: True
2018-07-03T08:46:49.1076460Z Stopping Windows Service:  and setting startup type to: Disabled. Kill: true
2018-07-03T08:46:49.1736460Z ##[debug]The following services were found: MyService
2018-07-03T08:46:49.4606460Z ##[debug]Leaving C:\vstsagent\A1\_work\_tasks\StopWindowsService_601cd43e-b65d-49b7-b118-091333bd5b9f\8.0.0\StopWindowsService.ps1.
2018-07-03T08:46:49.4756460Z ##[section]Finishing: Stop Windows Service: MyService

and psversiontable:

PS C:\Windows\system32> $psversiontable

Name                           Value
----                           -----
PSVersion                      5.0.10586.117
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.117
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

However using Manual or Automatic as startup type actually stops service, and process.

jabbera commented 6 years ago

Hi,

If you take a peek here: https://github.com/jabbera/my-vsts-tasks/blob/29985358579f799244e4be5f80a3e2c0180da436/Extensions/WindowsServiceReleaseTasks/Src/Tasks/StopWindowsService/StopWindowsServiceIntern.ps1#L39

You will see that the startup type has nothing to do with the service is stopping or not. Additionally if the service fails to stop, an exception is thrown and we would log it and force the process to terminate (as you have force kill set).

If the process is still in running after the stop task finishes (and it’s files are still busy) this typically means the service has returned from OnStop() but there are still non background threads running holding the process open. OnStop cannot exit until all non background threads are terminated.

Let me know if you are seeing something else.

Mike