Skip to content

Commit

Permalink
Merge pull request #6 from kenmaglio/VersionNext
Browse files Browse the repository at this point in the history
Releases 1.1.0
  • Loading branch information
kenmaglio authored Dec 7, 2016
2 parents e0e08b0 + a6e6dfe commit 9743f23
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 55 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
# cache/options directory
.vscode/

# git
.git/

# pkg
.pkg/
pkg/
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

## Versoin 1.1.0
### Published: 2016.12.07
#### Adds Enhancements
* Implements RunAs Capabilities
* Implements Interactive
* Refactors Service Defined Type to use Native Service Resource
* Refactors Service_ID to be Title of Resource for Install and Service Defined Types

#### Resolves Bugs
* Variable Namespacing for EPP
64 changes: 48 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
1. [Setup - The basics of getting started with winsw](#setup)
* [Beginning with winsw](#beginning-with-winsw)
1. [Usage - Configuration options and additional functionality](#usage)
* [Additional Configurations](#additional-configuration-parameters)
1. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
1. [Limitations - OS compatibility, etc.](#limitations)
1. [Development - Guide for contributing to the module](#development)
Expand Down Expand Up @@ -50,33 +51,51 @@ You can take two approaches:
## Usage

Usage Pattern for Installing and Configuring
Title = name of executable / service

<pre><code>
winsw::install { 'install_myservice':
winsw::install { 'MyService':
ensure => present,
winsw_binary_version => $winsw_binary_version,
install_path => $install_path,
service_id => $service_id,
service_name => $service_name,
service_executable => $service_executable,
service_argument_string => $service_argument_string,
} ->
winsw::service { 'MyService':
ensure => running,
}
</code></pre>

Optional Parameters
<pre><code>
winsw_binary_version => $winsw_binary_version,
install_path => $install_path,
service_description => $service_description,
service_env_variables => $service_env_variables,
service_logmode => $service_logmode,
} ->
winsw::service { 'run_myservice':
ensure => running,
service_id => $service_id,
}
</code></pre>

Usage Pattern for Uninstalling
<pre><code>
winsw::install { 'uninstall_myservice':
ensure => absent,
service_id => $service_id,
winsw::install { 'MyService':
ensure => absent,
}
</code></pre>

### Additional Configuration Parameters


To Specify Service Account to run service as
<pre><code>
service_user => 'your_serviceaccount',
service_pass => 'your_serviceaccount_password',
service_domain => 'your_serviceaccount_domain'
</code></pre>

To Run Interactively (not service account cannot be used - only local system)
<pre><code>
service_interactive => $true
</code></pre>

## Reference

The module includes embedded the winsw executable file, and provides a template for the configuration XML.
Expand Down Expand Up @@ -105,8 +124,21 @@ See: [https://github.com/kohsuke/winsw](https://github.com/kohsuke/winsw)

## Development

While using --modulepath does work, this approach I found easier
From directory C:\ProgramData\PuppetLabs\code\environments\production\modules
mklink /D winsw D:\[your git root dir]\winsw
#### Please fork and submit pull requests

To setup local environment:
<pre><code>
puppet module install puppetlabs-powershell --version 2.1.0 --modulepath=[your path to modules here]
puppet apply -v -e 'include winsw' --modulepath=[your path to modules here]
</code></pre>
You can include --noop if you don't want to apply, however service actions will fail as it won't actually install.

If you run an elevated command prompt, you can navigate to the service executable directory.
Then you can use these to test states of your service and the module. (note MyService is your servie name)
<pre><code>
MyService.exe stop
MyService.exe uninstall
MyService.exe start
MyService.exe install
</code></pre>

Then from D:\[your git root dir] in teminal: puppet apply .\winsw\
15 changes: 10 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,36 @@
class winsw (
$winsw_binary_version = $::winsw::params::winsw_binary_version,
$install_path = $::winsw::params::install_path,
$service_id = $::winsw::params::service_id,
$service_name = $::winsw::params::service_name,
$service_description = $::winsw::params::service_description,
$service_env_variables = $::winsw::params::service_env_variables,
$service_executable = $::winsw::params::service_executable,
$service_argument_string = $::winsw::params::service_argument_string,
$service_logmode = $::winsw::params::service_logmode,
$service_user = $::winsw::params::service_user,
$service_pass = $::winsw::params::service_pass,
$service_domain = $::winsw::params::service_domain,
$service_interactive = $::winsw::params::service_interactive,
) inherits ::winsw::params {

winsw::install { 'install_myservice':
winsw::install { 'MyService':
ensure => present,
winsw_binary_version => $winsw_binary_version,
install_path => $install_path,
service_id => $service_id,
service_name => $service_name,
service_executable => $service_executable,
service_argument_string => $service_argument_string,
service_description => $service_description,
service_env_variables => $service_env_variables,
service_logmode => $service_logmode,
service_user => $service_user,
service_pass => $service_pass,
service_domain => $service_domain,
service_interactive => $service_interactive,
} ->

winsw::service { 'run_myservice':
winsw::service { 'MyService':
ensure => running,
service_id => $service_id,
}

}
23 changes: 21 additions & 2 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
define winsw::install (
$ensure = present,
$service_id = undef,
$service_id = $title,
$service_name = undef,
$service_executable = undef,
$service_argument_string = undef,
Expand All @@ -12,6 +12,10 @@
$service_description = 'WinSW for Puppet',
$service_env_variables = undef,
$service_logmode = 'rotate',
$service_user = undef,
$service_pass = undef,
$service_domain = undef,
$service_interactive = false,
) {

if (!$service_id) {
Expand Down Expand Up @@ -80,7 +84,22 @@
# place the config file with the same name as the service - required for winsw
file { "config_xml_${service_id}":
ensure => $ensure,
content => epp('winsw/config.xml.epp'),
content => epp('winsw/config.xml.epp',{
'service_id' => $service_id,
'service_name' => $service_name,
'service_executable' => $service_executable,
'service_argument_string' => $service_argument_string,
'winsw_binary_version' => $winsw_binary_version,
'install_path' => $install_path,
'service_description' => $service_description,
'service_env_variables' => $service_env_variables,
'service_logmode' => $service_logmode,
'service_user' => $service_user,
'service_pass' => $service_pass,
'service_domain' => $service_domain,
'service_interactive' => $service_interactive
}
),
path => "${install_path}${service_id}.xml",
notify => $notify_config_change,
}
Expand Down
5 changes: 4 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
class winsw::params {
$winsw_binary_version = 'winsw_1_19_1'
$install_path = 'C:/Program Files/WinSW/'
$service_id = 'MyService'
$service_name = 'My Service'
$service_description = 'WinSW Service Wrapper'
$service_env_variables = undef
$service_executable = 'powershell'
$service_argument_string = ''
$service_logmode = 'rotate'
$service_user = undef
$service_pass = undef
$service_domain = undef
$service_interactive = false
}
25 changes: 7 additions & 18 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
#
define winsw::service (
$service_id = undef,
$service_id = $title,
$ensure = undef,
$install_path = 'C:/Program Files/WinSW/',
) {
Expand All @@ -14,23 +14,12 @@
fail('Ensure must be provided')
}

if ($ensure == running ) {
exec { "start_service_${service_id}":
command => "& '${install_path}${service_id}.exe' start",
unless => "\$started = (& '${install_path}${service_id}.exe' status); \
if (\$started -eq \"Started\") { exit 0 } else { exit 1 }",
provider => powershell,
}
}

if ($ensure == stopped ) {
exec { "stop_service_${service_id}":
command => "& '${install_path}${service_id}.exe' stop",
unless => "\$started = (& '${install_path}${service_id}.exe' status); \
if (\$installed -eq \"Stopped\") { exit 0 } else { exit 1 }",
refreshonly => true,
provider => powershell,
}
service { $service_id:
ensure => $ensure,
start => "${install_path}${service_id}.exe' start",
stop => "${install_path}${service_id}.exe' stop",
restart => "${install_path}${service_id}.exe' restart!",
status => "${install_path}${service_id}.exe' status",
}

}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kenmaglio-winsw",
"version": "1.0.1",
"version": "1.1.0",
"author": "Ken Maglio",
"summary": "WINSW Module. Service Wrapper for any process.",
"license": "MIT",
Expand Down
27 changes: 19 additions & 8 deletions templates/config.xml.epp
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<service>
<id><%= $winsw::service_id %></id>
<name><%= $winsw::service_name %></name>
<description><%= $winsw::service_description %></description>
<% if($winsw::service_env_variables) { -%>
<% each($winsw::service_env_variables) | $index, $var | { -%>
<id><%= $service_id %></id>
<name><%= $service_name %></name>
<description><%= $service_description %></description>
<% if($service_env_variables) { -%>
<% each($service_env_variables) | $index, $var | { -%>
<env name="<%= $var['name'] %>" value="<%= $var['value'] %>"/>
<% } -%>
<% } -%>
<executable><%= $winsw::service_executable %></executable>
<arguments><%= $winsw::service_argument_string %></arguments>
<logmode><%= $winsw::service_logmode %></logmode>
<executable><%= $service_executable %></executable>
<arguments><%= $service_argument_string %></arguments>
<logmode><%= $service_logmode %></logmode>
<% if($service_user) { -%>
<serviceaccount>
<domain><%= $service_domain %></domain>
<user><%= $service_user %></user>
<password><%= $service_pass %></password>
<allowservicelogon>true</allowservicelogon>
</serviceaccount>
<% } -%>
<% if($service_interactive) { -%>
<interactive />
<% } -%>
</service>

0 comments on commit 9743f23

Please sign in to comment.