Skip to content

Commit

Permalink
Merge pull request #1 from ecg-dk-siteops/Updated-windows-support
Browse files Browse the repository at this point in the history
Windows support update
  • Loading branch information
Jensen, Kristian(krjensen) authored and GitHub Enterprise committed Jan 24, 2019
2 parents a75a2bb + d08516c commit 7d78737
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 69 deletions.
4 changes: 0 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@
# [*manage_user*]
# Whether to create/manage the user that should own consul's configuration files.
#
# [*nssm_exec*]
# Location of nssm windows binary for service management
#
# [*os*]
# OS component in the name of the archive file containing the consul binary.
#
Expand Down Expand Up @@ -187,7 +184,6 @@
Boolean $manage_group = $consul::params::manage_group,
Boolean $manage_service = $consul::params::manage_service,
Boolean $manage_user = $consul::params::manage_user,
Optional[String] $nssm_exec = undef,
$os = $consul::params::os,
$package_ensure = $consul::params::package_ensure,
$package_name = $consul::params::package_name,
Expand Down
2 changes: 1 addition & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ensure => 'directory',
owner => $consul::user_real,
group => $consul::group_real,
mode => '0755',
mode => $consul::data_dir_mode,
}
}

Expand Down
28 changes: 19 additions & 9 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
class consul::params {
$acls = {}
$archive_path = '' #lint:ignore:empty_string_assignment
$bin_dir = '/usr/local/bin'
$checks = {}
$config_defaults = {}
$config_hash = {}
Expand All @@ -16,13 +15,10 @@
$download_url_base = 'https://releases.hashicorp.com/consul/'
$extra_groups = []
$extra_options = '' #lint:ignore:empty_string_assignment
$group = 'consul'
$log_file = '/var/log/consul'
$install_method = 'url'
$join_wan = false
$manage_group = true
$manage_service = true
$manage_user = true
$package_ensure = 'latest'
$package_name = 'consul'
$pretty_config = false
Expand All @@ -33,7 +29,6 @@
$service_ensure = 'running'
$services = {}
$service_config_hash = {}
$user = 'consul'
$version = '1.2.3'
$watches = {}

Expand All @@ -49,25 +44,40 @@

$config_dir = $facts['os']['family'] ? {
'FreeBSD' => '/usr/local/etc/consul.d',
'windows' => 'c:/Consul/config',
'windows' => 'C:\\ProgramData\\consul\\config',
default => '/etc/consul'
}

$bin_dir = $facts['os']['family'] ? {
'windows' => 'C:\\ProgramData\\consul',
default => '/usr/local/bin'
}

$os = downcase($facts['kernel'])

case $facts['os']['name'] {
'windows': {
$binary_group = 'Administrators'
$binary_mode = '0755'
$data_dir_mode = '0775'
$binary_group = undef
$binary_mode = '0775'
$binary_name = 'consul.exe'
$binary_owner = 'Administrator'
$binary_owner = 'NT AUTHORITY\NETWORK SERVICE'
$manage_user = false
$manage_group = false
$user = 'NT AUTHORITY\NETWORK SERVICE'
$group = 'Administrators'
}
default: {
# 0 instead of root because OS X uses "wheel".
$data_dir_mode = '0755'
$binary_group = 0
$binary_mode = '0555'
$binary_name = 'consul'
$binary_owner = 'root'
$manage_user = true
$manage_group = true
$user = 'consul'
$group = 'consul'
}
}

Expand Down
59 changes: 18 additions & 41 deletions manifests/windows_service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,28 @@
# Installs consul windows server
# == Parameters
#
# [*nssm_version*]
# nssm version to download
# [*sys32*]
# path to system32 folder
#
# [*nssm_download_url*]
# nssm version to download
# [*service_name*]
# Name of the service
#
# [*nssm_download_url_base*]
# nssm version to download
#
class consul::windows_service {

$app_dir = regsubst($consul::bin_dir, '\/', '\\', 'G')
$app_exec = "${app_dir}\\consul.exe"
$agent_args = regsubst($consul::config_dir, '\/', '\\', 'G')
$app_args = "agent -config-dir='${agent_args}' ${consul::extra_options}"
$app_log_path = "${app_dir}\\logs"
$app_log_file = 'consul.log'
$app_log = "${app_log_path}//${app_log_file}"

include 'archive'
class consul::windows_service (
$sys32 = 'c:\\windows\\system32',
$service_name = 'Consul'
)
{
$executable_file = "${consul::bin_dir}\\${consul::binary_name}"
$service_config = "start= auto binPath= \"${executable_file} agent -config-dir=${$consul::config_dir}\" obj= \"${consul::binary_owner}\""

file { $app_log_path:
ensure => 'directory',
owner => 'Administrator',
group => 'Administrators',
mode => '0755',
}
-> exec { 'consul_service_install':
cwd => $consul::bin_dir,
command => "&'${consul::nssm_exec}' install Consul ${app_exec}",
unless => 'if((get-service -name consul -ErrorAction SilentlyContinue).count -ne 1){exit 1}',
logoutput => true,
provider => 'powershell',
notify => Exec['consul_service_set_parameters'],
}
file { "${consul::bin_dir}/set_service_parameters.ps1":
ensure => 'present',
content => template('consul/set_service_parameters.ps1.erb'),
notify => Exec['consul_service_set_parameters'],
exec { 'create_consul_service':
command => "sc.exe create ${service_name} ${service_config}",
path => $sys32,
unless => "sc.exe query ${service_name}",
}
-> exec { 'consul_service_set_parameters':
cwd => $consul::bin_dir,
command => "& '${consul::bin_dir}/set_service_parameters.ps1'",
exec { 'update_consul_service':
command => "sc.exe config ${service_name} ${service_config}",
path => $sys32,
refreshonly => true,
logoutput => true,
provider => 'powershell',
}
}
14 changes: 0 additions & 14 deletions templates/set_service_parameters.ps1.erb

This file was deleted.

0 comments on commit 7d78737

Please sign in to comment.