added start mode feature

pull/18777/head
Hans-Joachim Kliemeck 9 years ago committed by Matt Clay
parent b2f666a2dd
commit 3ad86e383e

@ -33,6 +33,7 @@ $state = Get-Attr $params "state" "present" -validateSet "present", "absent", "s
$application = Get-Attr $params "application" $null $application = Get-Attr $params "application" $null
$appParameters = Get-Attr $params "app_parameters" $null $appParameters = Get-Attr $params "app_parameters" $null
$startMode = Get-Attr $params "start_mode" "auto" -validateSet "auto", "manual", "disabled" -resultobj $result
$stdoutFile = Get-Attr $params "stdout_file" $null $stdoutFile = Get-Attr $params "stdout_file" $null
$stderrFile = Get-Attr $params "stderr_file" $null $stderrFile = Get-Attr $params "stderr_file" $null
@ -403,6 +404,43 @@ Function Nssm-Update-Dependencies
} }
} }
Function Nssm-Update-StartMode
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$name,
[Parameter(Mandatory=$true)]
[string]$mode
)
$cmd = "nssm get ""$name"" Start"
$results = invoke-expression $cmd
if ($LastExitCode -ne 0)
{
Set-Attr $result "nssm_error_cmd" $cmd
Set-Attr $result "nssm_error_log" "$results"
Throw "Error updating start mode for service ""$name"""
}
$modes=@{"auto" = "SERVICE_AUTO_START"; "manual" = "SERVICE_DEMAND_START"; "disabled" = "SERVICE_DISABLED"}
$mappedMode = $modes.$mode
if ($mappedMode -ne $results) {
$cmd = "nssm set ""$name"" Start $mappedMode"
$results = invoke-expression $cmd
if ($LastExitCode -ne 0)
{
Set-Attr $result "nssm_error_cmd" $cmd
Set-Attr $result "nssm_error_log" "$results"
Throw "Error updating start mode for service ""$name"""
}
$result.changed = $true
}
}
Function Nssm-Get-Status Function Nssm-Get-Status
{ {
[CmdletBinding()] [CmdletBinding()]
@ -548,6 +586,7 @@ Try
Nssm-Set-Ouput-Files -name $name -stdout $stdoutFile -stderr $stderrFile Nssm-Set-Ouput-Files -name $name -stdout $stdoutFile -stderr $stderrFile
Nssm-Update-Dependencies -name $name -dependencies $dependencies Nssm-Update-Dependencies -name $name -dependencies $dependencies
Nssm-Update-Credentials -name $name -user $user -password $password Nssm-Update-Credentials -name $name -user $user -password $password
Nssm-Update-StartMode -name $name -mode $startMode
} }
"started" { "started" {
Nssm-Install -name $name -application $application Nssm-Install -name $name -application $application
@ -555,6 +594,7 @@ Try
Nssm-Set-Ouput-Files -name $name -stdout $stdoutFile -stderr $stderrFile Nssm-Set-Ouput-Files -name $name -stdout $stdoutFile -stderr $stderrFile
Nssm-Update-Dependencies -name $name -dependencies $dependencies Nssm-Update-Dependencies -name $name -dependencies $dependencies
Nssm-Update-Credentials -name $name -user $user -password $password Nssm-Update-Credentials -name $name -user $user -password $password
Nssm-Update-StartMode -name $name -mode $startMode
Nssm-Start -name $name Nssm-Start -name $name
} }
"stopped" { "stopped" {
@ -563,6 +603,7 @@ Try
Nssm-Set-Ouput-Files -name $name -stdout $stdoutFile -stderr $stderrFile Nssm-Set-Ouput-Files -name $name -stdout $stdoutFile -stderr $stderrFile
Nssm-Update-Dependencies -name $name -dependencies $dependencies Nssm-Update-Dependencies -name $name -dependencies $dependencies
Nssm-Update-Credentials -name $name -user $user -password $password Nssm-Update-Credentials -name $name -user $user -password $password
Nssm-Update-StartMode -name $name -mode $startMode
Nssm-Stop -name $name Nssm-Stop -name $name
} }
"restarted" { "restarted" {
@ -571,6 +612,7 @@ Try
Nssm-Set-Ouput-Files -name $name -stdout $stdoutFile -stderr $stderrFile Nssm-Set-Ouput-Files -name $name -stdout $stdoutFile -stderr $stderrFile
Nssm-Update-Dependencies -name $name -dependencies $dependencies Nssm-Update-Dependencies -name $name -dependencies $dependencies
Nssm-Update-Credentials -name $name -user $user -password $password Nssm-Update-Credentials -name $name -user $user -password $password
Nssm-Update-StartMode -name $name -mode $startMode
Nssm-Restart -name $name Nssm-Restart -name $name
} }
} }

@ -86,6 +86,19 @@ options:
- Password to be used for service startup - Password to be used for service startup
required: false required: false
default: null default: null
password:
description:
- Password to be used for service startup
required: false
default: null
start_mode:
description:
- If C(auto) is selected, the service will start at bootup. C(manual) means that the service will start only when another service needs it. C(disabled) means that the service will stay off, regardless if it is needed or not.
required: false
choices:
- auto
- manual
- disabled
author: author:
- "Adam Keech (@smadam813)" - "Adam Keech (@smadam813)"
- "George Frank (@georgefrank)" - "George Frank (@georgefrank)"
@ -151,6 +164,13 @@ EXAMPLES = '''
user: foouser user: foouser
password: secret password: secret
# Install the foo service but do not start it automatically
- win_nssm:
name: foo
application: C:\windows\\foo.exe
state: present
start_mode: manual
# Remove the foo service # Remove the foo service
- win_nssm: - win_nssm:
name: foo name: foo

Loading…
Cancel
Save