Puppet Class: mariadb::service

Defined in:
modules/mariadb/manifests/service.pp

Overview

Parameters:

  • package (Any) (defaults to: 'undefined')
  • basedir (Any) (defaults to: 'undefined')
  • manage (Any) (defaults to: false)
  • ensure (Any) (defaults to: stopped)
  • enable (Any) (defaults to: false)
  • override (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
137
138
# File 'modules/mariadb/manifests/service.pp', line 16

class mariadb::service (
    $package  = 'undefined',
    $basedir  = 'undefined',
    $manage   = false,
    $ensure   = stopped,
    $enable   = false,
    $override = false,
    ) {

    # default strech to mariadb 10.1, others to 10.0
    if os_version('debian >= stretch') and $package == 'undefined' {
        $installed_package = 'wmf-mariadb101'
    } elsif $package == 'undefined' {
        $installed_package = 'wmf-mariadb10'
    } else {
        $installed_package = $package
    }

    # mariadb 10.1 and later use systemd, others use init.d
    # Also identify vendor

    case $installed_package {
        'wmf-mariadb', 'wmf-mariadb10': {
            $systemd = false
            $vendor  = 'mariadb'
        }
        'wmf-mariadb101', 'wmf-mariadb102', 'wmf-mariadb103', 'wmf-mariadb104': {
            $systemd = true
            $vendor  = 'mariadb'
        }
        'wmf-mysql80': {
            $systemd = true
            $vendor = 'mysql'
        }
        'wmf-percona-server80': {
            $systemd = true
            $vendor = 'percona-server'
        }
        default: {
            fail("Invalid package version \"${installed_package}\". \
The only allowed versions are: wmf-mariadb10, wmf-mariadb101, wmf-mariadb102, \
wmf-mariadb103, wmf-mariadb104, wmf-percona-server80 or wmf-mysql80")
        }
    }

    if $systemd {
        # TODO: use the base::service configuration
        if $manage {
            service { $vendor:
                # $manage assumes only the main instance is managed-
                # multiple instances have to be managed manually
                ensure => $ensure,
                enable => $enable,
            }
        }
        # handle per-host special configuration
        if $override {
            file { "/etc/systemd/system/${vendor}.service.d":
                ensure => directory,
                mode   => '0755',
                owner  => 'root',
                group  => 'root',
            }
            file { "/etc/systemd/system/${vendor}.service.d/override.conf":
                ensure  => present,
                mode    => '0755',
                owner   => 'root',
                group   => 'root',
                content => $override,
                notify  => Exec['systemctl-daemon-reload'],
            }
            exec { 'systemctl-daemon-reload':
                command     => '/bin/systemctl daemon-reload',
                refreshonly => true,
            }
        } else {
            file { "/etc/systemd/system/${vendor}.service.d/override.conf":
                ensure => absent,
                notify => File["/etc/systemd/system/${vendor}.service.d"]
            }
            file { "/etc/systemd/system/${vendor}.service.d":
                ensure => absent,
            }
        }

    } else {
        # using still init.d
        if $basedir == 'undefined' {
            $initd_basedir = "/opt/${installed_package}"
        } else {
            $initd_basedir = $basedir
        }

        file { "${initd_basedir}/service":
            ensure  => present,
            owner   => 'root',
            group   => 'root',
            mode    => '0755',
            content => template('mariadb/mariadb.server.erb'),
            require => Package[$installed_package],
        }

        file { '/etc/init.d/mysql':
            ensure  => 'link',
            target  => "${initd_basedir}/service",
            require => File["${initd_basedir}/service"],
        }

        file { '/etc/init.d/mariadb':
            ensure  => 'link',
            target  => "${initd_basedir}/service",
            require => File["${initd_basedir}/service"],
        }

        if $manage {
            service { 'mysql':
                ensure  => $ensure,
                enable  => $enable,
                require => File['/etc/init.d/mysql'],
            }
        }
    }
}