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)
  • logging (Any) (defaults to: false)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
# File 'modules/haproxy/manifests/init.pp', line 16

class haproxy(
    $template = 'haproxy/haproxy.cfg.erb',
    $socket   = '/run/haproxy/haproxy.sock',
    $pid      = '/run/haproxy/haproxy.pid',
    $monitor  = true,
    $logging  = false,
) {

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

    # FIXME: Migrate to systemd::tmpfile
    if $socket == '/run/haproxy/haproxy.sock' or $pid == '/run/haproxy/haproxy.pid' {
        file { '/run/haproxy':
            ensure => directory,
            mode   => '0775',
            owner  => 'root',
            group  => 'haproxy',
        }
    }

    file { '/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  => Exec['restart-haproxy']
    }

    exec { 'restart-haproxy':
        command     => '/bin/systemctl restart haproxy',
        refreshonly => true,
    }

    # defaults file cannot be dynamic anymore on systemd
    # pregenerate them on systemd start/reload
    file { '/usr/local/bin/generate_haproxy_default.sh':
        ensure => present,
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
        source => 'puppet:///modules/haproxy/generate_haproxy_default.sh',
    }

    # TODO: this should use the general systemd puppet abstraction instead
    file { '/lib/systemd/system/haproxy.service':
        ensure  => present,
        mode    => '0644',
        owner   => 'root',
        group   => 'root',
        content => template('haproxy/haproxy.service.erb'),
        require => File['/usr/local/bin/generate_haproxy_default.sh'],
        notify  => Exec['/bin/systemctl daemon-reload'],
    }

    exec { '/bin/systemctl daemon-reload':
        user        => 'root',
        refreshonly => true,
    }

    if $monitor {
        file { '/usr/lib/nagios/plugins/check_haproxy':
            owner   => 'root',
            group   => 'root',
            mode    => '0755',
            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':
            description  => 'haproxy alive',
            nrpe_command => '/usr/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,
        }

    }

}