Puppet Class: wikistats::db

Defined in:
modules/wikistats/manifests/db.pp

Overview

the database server setup for the wikistats site

Parameters:

  • db_pass (String)
  • backupdir (Stdlib::Unixpath) (defaults to: '/usr/lib/wikistats/backup')


2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
# File 'modules/wikistats/manifests/db.pp', line 2

class wikistats::db (
    String $db_pass,
    Stdlib::Unixpath $backupdir = '/usr/lib/wikistats/backup',
) {

    if os_version('debian == buster') {
        require_package('php7.3-mysql')
    } else {
        require_package('php7.0-mysql')
    }

    # db backup
    cron { 'mysql-dump-wikistats':
        ensure  => 'present',
        command => "/usr/bin/mysqldump -u root wikistats > ${wikistats::db::backupdir}/wikistats_db_$(date +%Y%m%d).sql && gzip ${backupdir}/wikistats_db_$(date +%Y%m%d).sql",
        user    => 'root',
        hour    => '0',
        minute  => '15',
    }

    # don't run out of disk
    cron {'mysql-dump-wikistats-clean':
        ensure  => 'present',
        command => "find ${backupdir} -name \"*.sql.gz\" -mtime +7 -exec rm {} \\;",
        user    => 'root',
        hour    => '23',
        minute  => '23',
    }

    # (random) db pass is stored here to that deployment-script can
    # get it and replace it in the config file after deploying
    file { '/usr/lib/wikistats/wikistats-db-pass':
        ensure  => 'present',
        owner   => 'wikistatsuser',
        group   => 'wikistatsuser',
        mode    => '0400',
        content => $db_pass,
    }

    # database schema
    file { '/usr/lib/wikistats/schema.sql':
        ensure => 'present',
        owner  => 'wikistatsuser',
        group  => 'wikistatsuser',
        mode   => '0444',
        source => 'puppet:///modules/wikistats/schema.sql',
    }

    # import db schema on the first run
    exec { 'bootstrap-mysql-schema':
        command => '/usr/bin/mysql -u root -Bs < /usr/lib/wikistats/schema.sql',
        user    => 'root',
        timeout => '30',
        unless  => '/usr/bin/test -f /usr/lib/wikistats/db_init_done',
        before  => File['/usr/lib/wikistats/db_init_done'],
        require => File['/usr/lib/wikistats/schema.sql'],
    }

    file { '/usr/lib/wikistats/db_init_done':
        ensure  => 'present',
        content => 'database has been initialized',
        owner   => 'wikistatsuser',
        group   => 'wikistatsuser',
        mode    => '0444',
    }

    # grant db permissions on the first run

    file { '/usr/lib/wikistats/grants.sql':
        ensure  => 'present',
        content => template('wikistats/db/grants.sql.erb'),
        owner   => 'wikistatsuser',
        group   => 'wikistatsuser',
        mode    => '0444',
    }

    exec { 'bootstrap-mysql-grants':
        command => '/usr/bin/mysql -u root -Bs < /usr/lib/wikistats/grants.sql',
        user    => 'root',
        timeout => '30',
        unless  => '/usr/bin/test -f /usr/lib/wikistats/db_grants_done',
        before  => File['/usr/lib/wikistats/db_grants_done'],
        require => File['/usr/lib/wikistats/grants.sql'],
    }

    file { '/usr/lib/wikistats/db_grants_done':
        ensure  => 'present',
        content => 'database grants have been applied',
        owner   => 'wikistatsuser',
        group   => 'wikistatsuser',
        mode    => '0444',
    }

}