| 1 |
# @summary |
| 2 |
# HAProxy service |
| 3 |
# @api private |
| 4 |
define haproxy::service ( |
| 5 |
# lint:ignore:140chars |
| 6 |
String $instance_name, |
| 7 |
Variant[Enum['running', 'stopped'], Boolean] $service_ensure, |
| 8 |
Boolean $service_manage, |
| 9 |
Optional[String] $restart_command = undef, # A default is required for Puppet 2.7 compatibility. When 2.7 is no longer supported, this parameter default should be removed. << Update 16/12/22 default still required |
| 10 |
String $service_options = $haproxy::params::service_options, |
| 11 |
String $sysconfig_options = $haproxy::params::sysconfig_options, |
| 12 |
# lint:endignore |
| 13 |
) { |
| 14 |
if $caller_module_name != $module_name { |
| 15 |
fail("Use of private class ${name} by ${caller_module_name}") |
| 16 |
} |
| 17 |
|
| 18 |
if $service_manage { |
| 19 |
if ($facts['os']['family'] == 'Debian') { |
| 20 |
file { "/etc/default/${instance_name}": |
| 21 |
content => $service_options, |
| 22 |
before => Service[$instance_name], |
| 23 |
} |
| 24 |
} |
| 25 |
if ($facts['os']['family'] == 'Redhat') { |
| 26 |
file { "/etc/sysconfig/${instance_name}": |
| 27 |
content => $sysconfig_options, |
| 28 |
before => Service[$instance_name], |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
$_service_enable = $service_ensure ? { |
| 33 |
'running' => true, |
| 34 |
'stopped' => false, |
| 35 |
default => $service_ensure, |
| 36 |
} |
| 37 |
|
| 38 |
service { $instance_name: |
| 39 |
ensure => $service_ensure, |
| 40 |
enable => $_service_enable, |
| 41 |
name => $instance_name, |
| 42 |
hasrestart => true, |
| 43 |
hasstatus => true, |
| 44 |
restart => $restart_command, |
| 45 |
} |
| 46 |
} |
| 47 |
} |