Puppet Class: haproxy

Defined in:
modules/haproxy/manifests/init.pp

Overview

Parameters:

  • template (Any) (defaults to: 'haproxy/haproxy.cfg.erb')
  • socket (Any) (defaults to: '/run/haproxy/haproxy.sock')
  • pid (Any) (defaults to: '/run/haproxy/haproxy.pid')
  • monitor (Any) (defaults to: true)
  • monitor_check_haproxy (Any) (defaults to: true)
  • logging (Any) (defaults to: false)
  • systemd_override (Boolean) (defaults to: false)
  • systemd_content (Optional[String]) (defaults to: undef)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'modules/haproxy/manifests/init.pp', line 30

class haproxy(
    $template                         = 'haproxy/haproxy.cfg.erb',
    $socket                           = '/run/haproxy/haproxy.sock',
    $pid                              = '/run/haproxy/haproxy.pid',
    $monitor                          = true,
    $monitor_check_haproxy            = true,
    $logging                          = false,
    Boolean $systemd_override         = false,
    Optional[String] $systemd_content = undef,
) {

    package { [
        'socat',
        'haproxy',
    ]:
        ensure => present,
    }

    if $socket == '/run/haproxy/haproxy.sock' or $pid == '/run/haproxy/haproxy.pid' {
        systemd::tmpfile { 'haproxy':
            content => 'd /run/haproxy 0775 root haproxy',
        }
    }
    # /etc/haproxy is created by installing the haproxy package.
    # however manging ig in puppet means we can drop files into this directory
    # and not have to worry about dependencies as file objects get an auto require
    # for any managed parents directories
    file { ['/etc/haproxy', '/etc/haproxy/conf.d']:
        ensure => directory,
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    file { '/etc/haproxy/haproxy.cfg':
        ensure  => present,
        mode    => '0444',
        owner   => 'root',
        group   => 'root',
        content => template($template),
        notify  => Service['haproxy'],
    }

    # defaults file cannot be dynamic anymore on systemd
    # pregenerate them on systemd start/reload
    file { '/usr/local/bin/generate_haproxy_default.sh':
        ensure => absent,
    }

    # The ExecStart script is different on buster compared to earlier debians
    $exec_start = debian::codename::lt('buster') ? {
        true    => '/usr/sbin/haproxy-systemd-wrapper',
        default => '/usr/sbin/haproxy -Ws',
    }

    file { '/etc/default/haproxy':
        ensure  => present,
        mode    => '0644',
        owner   => 'root',
        group   => 'root',
        content => template('haproxy/haproxy.default.erb'),
        notify  => Service['haproxy'],
    }

    $systemd_service_content = $systemd_content? {
        undef   => template('haproxy/haproxy.service.erb'),
        default => $systemd_content,
    }

    systemd::service { 'haproxy':
        override       => $systemd_override,
        content        => $systemd_service_content,
        service_params => {'restart' => '/bin/systemctl reload haproxy.service',}
    }

    if $monitor {
        file { '/usr/lib/nagios/plugins/check_haproxy':
            ensure => absent,
        }

        nrpe::plugin { 'check_haproxy':
            ensure  => bool2str($monitor_check_haproxy, 'present', 'absent'),
            content => template('haproxy/check_haproxy.erb'),
        }

        nrpe::monitor_service { 'haproxy':
            description  => 'haproxy process',
            nrpe_command => '/usr/lib/nagios/plugins/check_procs -c 1: -C haproxy',
            notes_url    => 'https://wikitech.wikimedia.org/wiki/HAProxy',
        }

        nrpe::monitor_service { 'haproxy_alive':
            ensure       => bool2str($monitor_check_haproxy, 'present', 'absent'),
            description  => 'haproxy alive',
            nrpe_command => '/usr/local/lib/nagios/plugins/check_haproxy --check=alive',
            notes_url    => 'https://wikitech.wikimedia.org/wiki/HAProxy',
        }
    }

    if $logging {
        file { '/var/log/haproxy':
          ensure => directory,
          owner  => 'root',
          group  => 'adm',
          mode   => '0750',
        }

        logrotate::conf { 'haproxy':
          ensure => present,
          source => 'puppet:///modules/haproxy/haproxy.logrotate',
        }

        rsyslog::conf { 'haproxy':
          source   => 'puppet:///modules/haproxy/haproxy.rsyslog',
          priority => 49,
          require  => File['/var/log/haproxy'],
        }

        # The debian package originaly will cause the creation
        # of this file, it will be simply confusing if it remains there
        file { '/var/log/haproxy.log':
          ensure => absent,
        }

    }

}