From 46cd8ba7cde51aeb51abb8f78f4ecdc457470f98 Mon Sep 17 00:00:00 2001 From: Kira Rose Date: Thu, 24 Aug 2017 22:40:48 +1000 Subject: [PATCH] Check Windows service status before nssm STOP (#28379) * Check Windows service status before nssm STOP Add a condition on calling nssm STOP inside Nssm-Remove, to check whether or not a service has already been stopped. Currently nssm throws an exception: ``` failed: [...] (item=...) => {"changed": false, "failed": true, "item": "...", "msg": "an exception occurred when invoking NSSM: serviceName: STOP: The service has not been started."} failed: [...] (item=...) => {"changed": false, "failed": true, "item": "...", "msg": "an exception occurred when invoking NSSM: serviceName: The service has not been started."} ``` Behaviour after change: ``` ok: [...] => (item=...) ok: [...] => (item=...) ``` * Added named parameter to new Get-Service cmdlet --- lib/ansible/modules/windows/win_nssm.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/windows/win_nssm.ps1 b/lib/ansible/modules/windows/win_nssm.ps1 index 9b637b24d8..7d6fe43ae3 100644 --- a/lib/ansible/modules/windows/win_nssm.ps1 +++ b/lib/ansible/modules/windows/win_nssm.ps1 @@ -96,9 +96,10 @@ Function Nssm-Remove if (Service-Exists -name $name) { - $cmd = "stop ""$name""" - $results = Nssm-Invoke $cmd - + if ((Get-Service -Name $name).Status -ne "Stopped") { + $cmd = "stop ""$name""" + $results = Nssm-Invoke $cmd + } $cmd = "remove ""$name"" confirm" $results = Nssm-Invoke $cmd @@ -695,4 +696,4 @@ Try Catch { Fail-Json $result $_.Exception.Message -} \ No newline at end of file +}