Skip to content

Commit

Permalink
Merge pull request #1194 from elfranne/debian-dirs
Browse files Browse the repository at this point in the history
Fix binarylog by allowing users to specify managed directories
  • Loading branch information
carabasdaniel authored Mar 20, 2020
2 parents 312aca8 + 1226228 commit 84069b0
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 28 deletions.
11 changes: 11 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
$managed_dirs = undef
# mysql::bindings
$perl_package_name = 'perl-DBD-MySQL'
$php_package_name = 'php-mysql'
Expand Down Expand Up @@ -172,6 +173,7 @@
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
$managed_dirs = undef
# mysql::bindings
$java_package_name = 'mysql-connector-java'
$perl_package_name = 'perl-DBD-mysql'
Expand Down Expand Up @@ -220,6 +222,8 @@
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
$managed_dirs = ['tmpdir','basedir','datadir','innodb_data_home_dir','innodb_log_group_home_dir','innodb_undo_directory','innodb_tmpdir']

# mysql::bindings
if $::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '10') >= 0 {
$java_package_name = 'libmariadb-java'
Expand Down Expand Up @@ -267,6 +271,7 @@
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
$managed_dirs = undef
# mysql::bindings
$java_package_name = 'mysql-connector-java'
$perl_package_name = 'perl-dbd-mysql'
Expand Down Expand Up @@ -294,6 +299,7 @@
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
$managed_dirs = undef
# mysql::bindings
$java_package_name = 'dev-java/jdbc-mysql'
$perl_package_name = 'dev-perl/DBD-mysql'
Expand Down Expand Up @@ -321,6 +327,7 @@
$ssl_cert = undef
$ssl_key = undef
$tmpdir = '/tmp'
$managed_dirs = undef
# mysql::bindings
$java_package_name = 'databases/mysql-connector-java'
$perl_package_name = 'p5-DBD-mysql'
Expand Down Expand Up @@ -351,6 +358,7 @@
$ssl_cert = undef
$ssl_key = undef
$tmpdir = '/tmp'
$managed_dirs = undef
# mysql::bindings
$java_package_name = undef
$perl_package_name = 'p5-DBD-mysql'
Expand All @@ -377,6 +385,7 @@
$ssl_cert = undef
$ssl_key = undef
$tmpdir = '/tmp'
$managed_dirs = undef
# mysql::bindings
$java_package_name = undef
$perl_package_name = undef
Expand Down Expand Up @@ -408,6 +417,7 @@
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
$managed_dirs = undef
$java_package_name = undef
$perl_package_name = 'perl-dbd-mysql'
$php_package_name = 'php7-mysqlnd'
Expand Down Expand Up @@ -435,6 +445,7 @@
$ssl_cert = '/etc/mysql/server-cert.pem'
$ssl_key = '/etc/mysql/server-key.pem'
$tmpdir = '/tmp'
$managed_dirs = undef
# mysql::bindings
$java_package_name = 'mysql-connector-java'
$perl_package_name = 'perl-DBD-MySQL'
Expand Down
4 changes: 2 additions & 2 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@

include '::mysql::server::config'
include '::mysql::server::install'
include '::mysql::server::binarylog'
include '::mysql::server::managed_dirs'
include '::mysql::server::installdb'
include '::mysql::server::service'
include '::mysql::server::root_password'
Expand All @@ -164,7 +164,7 @@
Anchor['mysql::server::start']
-> Class['mysql::server::config']
-> Class['mysql::server::install']
-> Class['mysql::server::binarylog']
-> Class['mysql::server::managed_dirs']
-> Class['mysql::server::installdb']
-> Class['mysql::server::service']
-> Class['mysql::server::root_password']
Expand Down
26 changes: 0 additions & 26 deletions manifests/server/binarylog.pp

This file was deleted.

20 changes: 20 additions & 0 deletions manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

$options = $mysql::server::_options
$includedir = $mysql::server::includedir
$managed_dirs = $mysql::server::managed_dirs


File {
owner => 'root',
Expand All @@ -33,6 +35,24 @@
}
}

#Debian: Creating world readable directories before installing.
if $managed_dirs {
$managed_dirs.each | $entry | {
$dir = $options['mysqld']["${entry}"]
if ( $dir and $dir != '/usr' and $dir != '/tmp' ) {
exec {"${entry}-managed_dir-mkdir":
command => "/bin/mkdir -p ${dir}",
unless => "/usr/bin/dpkg -s ${mysql::server::package_name}",
notify => Exec["${entry}-managed_dir-chmod"],
}
exec {"${entry}-managed_dir-chmod":
command => "/bin/chmod 777 ${dir}",
refreshonly => true,
}
}
}
}

if $mysql::server::manage_config_file {
file { 'mysql-config-file':
path => $mysql::server::config_file,
Expand Down
44 changes: 44 additions & 0 deletions manifests/server/managed_dirs.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# @summary
# Binary log configuration requires the mysql user to be present. This must be done after package install
#
# @api private
#
class mysql::server::managed_dirs {

$options = $mysql::server::_options
$includedir = $mysql::server::includedir
$managed_dirs = $mysql::server::managed_dirs

#Debian: Fix permission on directories
if $managed_dirs {
$managed_dirs_path = $managed_dirs.map |$path| { $options['mysqld']["${path}"] }
$managed_dirs.each | $entry | {
$dir = $options['mysqld']["${entry}"]
if ( $dir and $dir != '/usr' and $dir != '/tmp' ) {
file {"${entry}-managed_dir":
ensure => directory,
path => $dir,
mode => '0700',
owner => $options['mysqld']['user'],
group => $options['mysqld']['user'],
}
}
}
}

$logbin = pick($options['mysqld']['log-bin'], $options['mysqld']['log_bin'], false)

if $logbin {
$logbindir = dirname($logbin)

#Stop puppet from managing directory if just a filename/prefix is specified or is not already managed
if ($logbindir != '.' and !($logbindir in $managed_dirs_path)) {
file { $logbindir:
ensure => directory,
mode => '0700',
owner => $options['mysqld']['user'],
group => $options['mysqld']['user'],
}
}
}
}

0 comments on commit 84069b0

Please sign in to comment.