Skip to content

Commit

Permalink
Merge pull request #2 from ktreese/hardcoded_path_refactor
Browse files Browse the repository at this point in the history
Hardcoded path refactor
  • Loading branch information
ktreese authored Nov 20, 2016
2 parents 2844dc0 + d51c724 commit 4c98dbe
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@

## Overview

This module is a couple of defined types to install a service, and set the parameters for that service. This will obviously require NSSM to be installed
This module contains a couple of defined types:
- `nssm::install` install a service
- `nssm::set` set the parameters for that service

#### Installing NSSM

This will obviously require NSSM to be installed. If you need to install nssm, you may optionally declare the nssm class:

`include nssm`

Note, however, that the `nssm` class is simply declaring the [windows::nssm](https://forge.puppet.com/counsyl/windows#windowsnssm) class, which already does an excellent job of downloading and installing nssm, so understand `counsyl/windows` as a dependency to using my `nssm` class.

If you already have nssm installed, a default path to the nssm exe is assumed as `C:\Program Files\nssm-2.24\win64`. This may be overridden if your PATH differs by supplying `nssm_path` as an attribute to the `nssm:install` and `nssm::set` defined types.

## Module Description

Expand Down
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Simply declares windows:nssm to download and install nssm
# This requires the counsyl/windows puppet module
#
# Note you do not have to declare the nssm class if you
# already have nssm installed
class nssm {
include windows::nssm
}
9 changes: 7 additions & 2 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@
# [*service_name*]
# name of the service to display in services.msc
#
# [*nssm_path*]
# PATH to nssm exe
# defaults to C:\Program Files\nssm-2.24\win64
#
define nssm::install (
$ensure = undef,
$program = undef,
$service_name = $title,
$nssm_path = 'C:\Program Files\nssm-2.24\win64',
) {

if $ensure == present {
exec { 'install_service_name':
command => "nssm install '${service_name}' '${program}'",
path => 'C:\Program Files\nssm-2.24\win64',
path => $nssm_path,
unless => "nssm get '${service_name}' Name",
provider => powershell,
}
Expand All @@ -33,7 +38,7 @@
if $ensure == absent {
exec { 'remove_service_name':
command => "nssm remove '${service_name}' confirm",
path => 'C:\Program Files\nssm-2.24\win64',
path => $nssm_path,
onlyif => "nssm get '${service_name}' Name",
provider => powershell,
}
Expand Down
11 changes: 8 additions & 3 deletions manifests/set.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
# Allow service to interact with desktop
# Defaults to false
#
# [*nssm_path*]
# PATH to nssm exe
# defaults to C:\Program Files\nssm-2.24\win64
#
define nssm::set (
$create_user = false,
$service_name = $title,
$service_user = 'LocalSystem',
$service_pass = undef,
$service_interactive = false,
$app_parameters = undef,
$nssm_path = 'C:\Program Files\nssm-2.24\win64',
) {

if $create_user {
Expand All @@ -41,22 +46,22 @@
# http://grokbase.com/t/gg/salt-users/152vyb5vx1/weird-whitespace-problem-getting-data-out-of-cmd-run-nssm-on-windows
exec { 'set_service_name':
command => $command,
path => 'C:\Program Files\nssm-2.24\win64',
path => $nssm_path,
unless => "[Console]::OutputEncoding = [System.Text.Encoding]::Unicode; \$args = nssm get '${service_name}' ObjectName; \$cmp = \$args.Contains(\"${service_user}\"); if (\$cmp -eq \"True\") {exit 0} else {exit 1}",
provider => powershell,
}

exec { 'set_app_parameters':
command => "nssm set '${service_name}' AppParameters '${app_parameters}'",
path => 'C:\Program Files\nssm-2.24\win64',
path => $nssm_path,
unless => "[Console]::OutputEncoding = [System.Text.Encoding]::Unicode; \$args = nssm get '${service_name}' AppParameters; \$cmp = \$args.Contains(\"${app_parameters}\"); if (\$cmp -eq \"True\") {exit 0} else {exit 1}",
provider => powershell,
}

if $service_interactive {
exec { 'set_service_interactive_process':
command => "nssm reset '${service_name}' ObjectName; nssm set '${service_name}' Type SERVICE_INTERACTIVE_PROCESS",
path => 'C:\Program Files\nssm-2.24\win64',
path => $nssm_path,
unless => "[Console]::OutputEncoding = [System.Text.Encoding]::Unicode; \$args = nssm get '${service_name}' Type; \$cmp = \$args.Contains(\"INTERACTIVE\"); if (\$cmp -eq \"True\") {exit 0} else {exit 1}",
provider => powershell,
}
Expand Down

0 comments on commit 4c98dbe

Please sign in to comment.