Puppet Class: wikistats::db
- Defined in:
- modules/wikistats/manifests/db.pp
Overview
SPDX-License-Identifier: Apache-2.0 the database server setup for the wikistats site
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 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 |
# File 'modules/wikistats/manifests/db.pp', line 3
class wikistats::db (
Wmflib::Php_version $php_version,
String $db_pass,
String $db_name = 'wikistats',
Stdlib::Unixpath $backupdir = '/usr/lib/wikistats/backup',
Stdlib::Unixpath $backupdir_ext = '/srv/wikistats/backup',
String $dumpname = 'wikistats_db',
Stdlib::Unixpath $mysqldump = '/usr/bin/mysqldump',
){
ensure_packages("php${php_version}-mysql")
# db backup
wmflib::dir::mkdir_p('/usr/local/bin/wikistats')
file { '/usr/local/bin/wikistats/dbdump.sh':
ensure => present,
owner => 'wikistatsuser',
group => 'root',
mode => '0554',
source => 'puppet:///modules/wikistats/dbdump.sh',
}
wmflib::dir::mkdir_p('/etc/wikistats')
file { '/etc/wikistats/dbdump.cfg':
ensure => present,
owner => 'wikistatsuser',
group => 'wikistatsuser',
mode => '0444',
content => template('wikistats/dbdump.cfg.erb'),
}
systemd::timer::job { 'wikistats-dbdump':
ensure => present,
user => 'root',
description => 'create a database backup',
command => '/usr/local/bin/wikistats/dbdump.sh',
logging_enabled => true,
logfile_basedir => '/var/log/wikistats/',
logfile_name => 'dbdump.log',
interval => {'start' => 'OnCalendar', 'interval' => '*-*-* 0:15:00'},
}
# don't run out of disk
systemd::timer::job { 'wikistats-cleanup-mysqldump':
ensure => present,
user => 'root',
description => 'delete old dump files to avoid running out of disk space',
command => "/usr/bin/find ${backupdir} -name \"*.sql.gz\" -mtime +7 -exec rm {} \\;",
logging_enabled => true,
logfile_basedir => '/var/log/wikistats/',
logfile_name => 'cleanup-mysqldump.log',
interval => {'start' => 'OnCalendar', 'interval' => '*-*-* 23:23:00'},
}
# copy local backups to external cinder volume
systemd::timer::job { 'wikistats-backup-external':
ensure => present,
user => 'root',
description => 'copy database backups to external cinder volume',
command => "/usr/bin/rsync --delete --exclude lost+found -avp ${backupdir} ${backupdir_ext}",
logging_enabled => false,
interval => {'start' => 'OnCalendar', 'interval' => '*-*-* 0:30:00'},
}
# (random) db pass is stored here to that deployment-script can
# get it and replace it in the config file after deploying
wmflib::dir::mkdir_p('/usr/lib/wikistats')
file { '/usr/lib/wikistats/wikistats-db-pass':
ensure => present,
owner => 'wikistatsuser',
group => 'wikistatsuser',
mode => '0400',
content => $db_pass,
}
# copy backups to external cinder volume
# attach cinder volume 'backup' to instance in Horizon
# mounts any volume larger than 1 and smaller than 2 GB
wmflib::dir::mkdir_p($backupdir_ext)
cinderutils::ensure { 'cinder_backup_volume':
mount_point => $backupdir_ext,
min_gb => 0.9,
max_gb => 1.5,
}
# 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',
}
}
|