Skip to content

Commit

Permalink
Add option to set the service's name
Browse files Browse the repository at this point in the history
This is being added to support using the software collection for haproxy
on CentOS. Before this change both the name of the service being managed
and the sysconfig file for the service were incorrect and could not be
coaxed into a valid state.
  • Loading branch information
genebean committed Dec 26, 2018
1 parent 2e1d158 commit f64ece9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [Beginning with haproxy](#beginning-with-haproxy)
4. [Usage - Configuration options and additional functionality](#usage)
* [Configure HAProxy options](#configure-haproxy-options)
* [HAProxy and Software Collections](#haproxy-and-software-collections)
* [Configure HAProxy daemon listener](#configure-haproxy-daemon-listener)
* [Configure multi-network daemon listener](#configure-multi-network-daemon-listener)
* [Configure HAProxy load-balanced member nodes](#configure-haproxy-load-balanced-member-nodes)
Expand Down Expand Up @@ -128,6 +129,22 @@ class { 'haproxy':
}
~~~

### HAProxy and Software Collections

To use this module with a software collection such as
[rh-haproxy18](https://www.softwarecollections.org/en/scls/rhscl/rh-haproxy18/)
you will need to set a few extra parameters like so:

~~~puppet
class { 'haproxy':
package_name => 'rh-haproxy18',
config_dir => '/etc/opt/rh/rh-haproxy18/haproxy',
config_file => '/etc/opt/rh/rh-haproxy18/haproxy/haproxy.cfg',
config_validate_cmd => '/bin/scl enable rh-haproxy18 "haproxy -f % -c"',
service_name => 'rh-haproxy18-haproxy',
}
~~~

### Configure HAProxy daemon listener

To export the resource for a balancermember and collect it on a single HAProxy load balancer server:
Expand Down Expand Up @@ -599,6 +616,8 @@ Main class, includes all other classes.

* `service_manage`: Specifies whether the state of the HAProxy service should be managed by Puppet. Valid options: 'true' and 'false'. Default: 'true'.

* `service_name`: Specifies the name of the HAProxy service. Valid options: a string. Default: 'haproxy'.

* `service_options`: Contents for the `/etc/defaults/haproxy` file on Debian. Defaults to "ENABLED=1\n" on Debian, and is ignored on other systems.

* `sysconfig_options`: Contents for the `/etc/sysconfig/haproxy` file on RedHat(-based) systems. Defaults to OPTIONS="" on RedHat(-based) systems and is ignored on others
Expand Down Expand Up @@ -861,6 +880,11 @@ stopped and disabled at boot. Defaults to 'running'
Chooses whether the haproxy service state should be managed by puppet at
all. Defaults to true

* `service_name`:
The service name for haproxy. Defaults to undef. If no name is given then
the value computed for $instance_name will be used.
NOTE: Class['haproxy'] has a different default.

* `global_options`:
A hash of all the haproxy global options. If you want to specify more
than one option (i.e. multiple timeout or stats options), pass those
Expand Down
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
# Chooses whether the haproxy service state should be managed by puppet at
# all. Defaults to true
#
# [*service_name*]
# The service name for haproxy. Defaults to 'haproxy'
# NOTE: haproxy::instance has a different default.
#
# [*service_options*]
# Contents for the `/etc/defaults/haproxy` file on Debian. Defaults to "ENABLED=1\n" on Debian, and is ignored on other systems.
#
Expand Down Expand Up @@ -113,6 +117,7 @@
String $package_name = $haproxy::params::package_name,
Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running',
Boolean $service_manage = true,
String $service_name = $haproxy::params::service_name,
String $service_options = $haproxy::params::service_options,
$sysconfig_options = $haproxy::params::sysconfig_options,
Hash $global_options = $haproxy::params::global_options,
Expand Down Expand Up @@ -163,6 +168,7 @@
package_name => $package_name,
service_ensure => $_service_ensure,
service_manage => $_service_manage,
service_name => $service_name,
global_options => $global_options,
defaults_options => $defaults_options,
restart_command => $restart_command,
Expand Down
10 changes: 9 additions & 1 deletion manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
# Chooses whether the haproxy service state should be managed by puppet at
# all. Defaults to true
#
# [*service_name*]
# The service name for haproxy. Defaults to undef. If no name is given then
# the value computed for $instance_name will be used.
# NOTE: Class['haproxy'] has a different default.
#
# [*global_options*]
# A hash of all the haproxy global options. If you want to specify more
# than one option (i.e. multiple timeout or stats options), pass those
Expand Down Expand Up @@ -144,6 +149,7 @@
String[1] $package_ensure = 'present',
Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running',
Boolean $service_manage = true,
Optional[String] $service_name = undef,
Optional[Hash] $global_options = undef,
Optional[Hash] $defaults_options = undef,
$restart_command = undef,
Expand Down Expand Up @@ -188,6 +194,8 @@
$_config_dir = pick($config_dir, inline_template($haproxy::params::config_dir_tmpl))
}

$instance_service_name = pick($service_name, $instance_name)

haproxy::config { $title:
instance_name => $instance_name,
config_dir => $_config_dir,
Expand All @@ -204,7 +212,7 @@
package_ensure => $package_ensure,
}
haproxy::service { $title:
instance_name => $instance_name,
instance_name => $instance_service_name,
service_ensure => $service_ensure,
service_manage => $service_manage,
restart_command => $restart_command,
Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
case $::osfamily {
'Archlinux', 'Debian', 'Redhat', 'Gentoo', 'Suse' : {
$package_name = 'haproxy'
$service_name = 'haproxy'
$global_options = {
'log' => "${::ipaddress} local0",
'chroot' => '/var/lib/haproxy',
Expand Down Expand Up @@ -50,6 +51,7 @@
}
'FreeBSD': {
$package_name = 'haproxy'
$service_name = 'haproxy'
$global_options = {
'log' => [
'127.0.0.1 local0',
Expand Down

0 comments on commit f64ece9

Please sign in to comment.