Puppet Class: community_civicrm::db
- Defined in:
- modules/community_civicrm/manifests/db.pp
Summary
the database server setup for the community_civicrm siteOverview
SPDX-License-Identifier: Apache-2.0
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 |
# File 'modules/community_civicrm/manifests/db.pp', line 13
class community_civicrm::db (
Wmflib::Php_version $php_version,
Stdlib::Host $db_host = 'localhost',
String $db_user = 'civiadmin',
String $db_pass = 'FAKEFAKEFAKE',
String $db_name = 'drupal',
Stdlib::Unixpath $file_root = '/usr/lib/community_civicrm',
Stdlib::Unixpath $backupdir = "${file_root}/backup",
Stdlib::Unixpath $mysqldump = '/usr/bin/mysqldump',
){
ensure_packages("php${php_version}-mysql")
# value used in naming the db dump file
$dumpname = 'community_civicrm_db'
# db backup
file { '/usr/local/bin/community_civicrm-dbdump':
ensure => present,
owner => 'civiadmin',
mode => '0554',
source => 'puppet:///modules/community_civicrm/dbdump.sh',
}
wmflib::dir::mkdir_p('/etc/community_civicrm')
file { '/etc/community_civicrm/dbdump.cfg':
ensure => present,
owner => 'civiadmin',
group => 'civiadmin',
mode => '0444',
content => template('community_civicrm/dbdump.cfg.erb'),
}
wmflib::dir::mkdir_p('/var/log/community_civicrm')
systemd::timer::job { 'community_civicrm-dbdump':
ensure => present,
user => 'root',
description => 'create a database backup',
command => '/usr/local/bin/community_civicrm-dbdump',
logging_enabled => true,
logfile_basedir => '/var/log/community_civicrm/',
logfile_name => 'dbdump.log',
interval => {'start' => 'OnCalendar', 'interval' => '*-*-* 0:15:00'},
}
# don't run out of disk
systemd::timer::job { 'community_civicrm-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/community_civicrm/',
logfile_name => 'cleanup-mysqldump.log',
interval => {'start' => 'OnCalendar', 'interval' => '*-*-* 23:23: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($file_root)
file { "${file_root}/community_civicrm-db-pass":
ensure => present,
owner => 'civiadmin',
group => 'civiadmin',
mode => '0400',
content => $db_pass,
show_diff => false,
}
# database schema
file { "${file_root}/schema.sql":
ensure => present,
owner => 'civiadmin',
group => 'civiadmin',
mode => '0444',
source => 'puppet:///modules/community_civicrm/schema.sql',
}
# import db schema on the first run
exec { 'bootstrap-mysql-schema':
command => "/usr/bin/mysql -u root -Bs < ${file_root}/schema.sql",
user => 'root',
timeout => '30',
unless => "/usr/bin/mysql -u root -Bs -D${db_name} -e 'describe civicrm_setting'",
creates => "${file_root}/db_init_done",
require => File["${file_root}/schema.sql"],
}
file { "${file_root}/db_init_done":
ensure => present,
content => 'database has been initialized',
owner => 'civiadmin',
group => 'civiadmin',
mode => '0444',
}
# grant db permissions on the first run
file { "${file_root}/grants.sql":
ensure => present,
content => template('community_civicrm/db/grants.sql.erb'),
owner => 'civiadmin',
group => 'civiadmin',
mode => '0444',
show_diff => false,
}
exec { 'bootstrap-mysql-grants':
command => "/usr/bin/mysql -u root -Bs < ${file_root}/grants.sql",
user => 'root',
timeout => '30',
unless => "/usr/bin/mysql -u root -Bs -e 'show grants for \'${db_user}\'@\'${db_host}\''",
require => File["${file_root}/grants.sql"],
}
}
|