From 1b4eea79d8c08a01fd7b47773e77ea1ae1c80413 Mon Sep 17 00:00:00 2001 From: Hans-Joachim Kliemeck Date: Thu, 27 Oct 2016 11:56:08 +0200 Subject: [PATCH] win_nssm: set application directory on change of application binary (#3267) --- .../modules/extras/windows/win_nssm.ps1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/ansible/modules/extras/windows/win_nssm.ps1 b/lib/ansible/modules/extras/windows/win_nssm.ps1 index 2c7db8dfa7..3ea4a211c3 100644 --- a/lib/ansible/modules/extras/windows/win_nssm.ps1 +++ b/lib/ansible/modules/extras/windows/win_nssm.ps1 @@ -95,6 +95,9 @@ Function Nssm-Install { Throw "Error installing service ""$name"". No application was supplied." } + If (-Not (Test-Path -Path $application -PathType Leaf)) { + Throw "$application does not exist on the host" + } if (!(Service-Exists -name $name)) { @@ -138,6 +141,21 @@ Function Nssm-Install $result.changed = $true } } + + if ($result.changed) + { + $applicationPath = (Get-Item $application).DirectoryName + $cmd = "nssm set ""$name"" AppDirectory $applicationPath" + + $results = invoke-expression $cmd + + if ($LastExitCode -ne 0) + { + Set-Attr $result "nssm_error_cmd" $cmd + Set-Attr $result "nssm_error_log" "$results" + Throw "Error installing service ""$name""" + } + } } Function ParseAppParameters()