mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
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
This commit is contained in:
parent
e7a525bd4a
commit
46cd8ba7cd
1 changed files with 5 additions and 4 deletions
|
@ -96,9 +96,10 @@ Function Nssm-Remove
|
||||||
|
|
||||||
if (Service-Exists -name $name)
|
if (Service-Exists -name $name)
|
||||||
{
|
{
|
||||||
$cmd = "stop ""$name"""
|
if ((Get-Service -Name $name).Status -ne "Stopped") {
|
||||||
$results = Nssm-Invoke $cmd
|
$cmd = "stop ""$name"""
|
||||||
|
$results = Nssm-Invoke $cmd
|
||||||
|
}
|
||||||
$cmd = "remove ""$name"" confirm"
|
$cmd = "remove ""$name"" confirm"
|
||||||
$results = Nssm-Invoke $cmd
|
$results = Nssm-Invoke $cmd
|
||||||
|
|
||||||
|
@ -695,4 +696,4 @@ Try
|
||||||
Catch
|
Catch
|
||||||
{
|
{
|
||||||
Fail-Json $result $_.Exception.Message
|
Fail-Json $result $_.Exception.Message
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue