From 35c351f926b9e0f38d308b5af8cc27001b39f3bf Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Sun, 6 Apr 2014 17:07:47 -0400 Subject: Cron jobs are not removed when unused. Currently, if you have the bad idea of setting backup_cron or optimize_cron to true in the main class and later to change it back to false, the associated cronjob will stay in place even though you don't want it. To make this option more consistant, let's remove cron jobs (and backup helper scripts) when the appropriate option is set to false. Signed-off-by: Gabriel Filion --- manifests/server/backup_helpers.pp | 13 ++++++++----- manifests/server/base.pp | 25 ++++++++++++++++--------- manifests/server/cron/backup.pp | 5 ++++- manifests/server/cron/optimize.pp | 15 +++++++++------ 4 files changed, 37 insertions(+), 21 deletions(-) (limited to 'manifests/server') diff --git a/manifests/server/backup_helpers.pp b/manifests/server/backup_helpers.pp index 564e2ab..f9861cf 100644 --- a/manifests/server/backup_helpers.pp +++ b/manifests/server/backup_helpers.pp @@ -1,11 +1,14 @@ # Helpers for mysql servers # In a dedicated class so they can # also be pulled in somewhere else -class mysql::server::backup_helpers{ +class mysql::server::backup_helpers ( + $ensure = present +) { file{'/usr/local/bin/mysql_extract_from_backup': - source => 'puppet:///modules/mysql/backup_helpers/mysql_extract_from_backup.sh', - owner => root, - group => 0, - mode => '0555'; + ensure => $ensure, + source => 'puppet:///modules/mysql/backup_helpers/mysql_extract_from_backup.sh', + owner => root, + group => 0, + mode => '0555'; } } diff --git a/manifests/server/base.pp b/manifests/server/base.pp index 7bbf30d..0ac74f2 100644 --- a/manifests/server/base.pp +++ b/manifests/server/base.pp @@ -64,17 +64,24 @@ class mysql::server::base { refreshonly => true, } - if $mysql::server::backup_cron { - include mysql::server::cron::backup - include mysql::server::backup_helpers + $backup_ensure = $mysql::server::backup_cron ? { + true => present, + false => absent, } - if $mysql::server::optimize_cron { - class { 'mysql::server::cron::optimize': - optimize_hour => $mysql::server::optimize_hour, - optimize_minute => $mysql::server::optimize_minute, - optimize_day => $mysql::server::optimize_day, - } + class { 'mysql::server::cron::backup': ensure => $backup_ensure } + class { 'mysql::server::backup_helpers': ensure => $backup_ensure } + + $cron_ensure = $mysql::server::optimize_cron ? { + true => present, + false => absent, + } + + class { 'mysql::server::cron::optimize': + ensure => $cron_ensure, + optimize_hour => $mysql::server::optimize_hour, + optimize_minute => $mysql::server::optimize_minute, + optimize_day => $mysql::server::optimize_day, } service { 'mysql': diff --git a/manifests/server/cron/backup.pp b/manifests/server/cron/backup.pp index 671ad9c..463cd29 100644 --- a/manifests/server/cron/backup.pp +++ b/manifests/server/cron/backup.pp @@ -1,5 +1,7 @@ # setup a basic cronjob to backup mysql database -class mysql::server::cron::backup { +class mysql::server::cron::backup ( + $ensure = present, +) { if $mysql::server::manage_backup_dir { file { 'mysql_backup_dir': ensure => directory, @@ -12,6 +14,7 @@ class mysql::server::cron::backup { } cron { 'mysql_backup_cron': + ensure => $ensure, command => "/usr/bin/mysqldump --default-character-set=utf8 --all-databases --create-options --flush-logs --lock-tables --single-transaction | gzip > ${mysql::server::backup_dir}/mysqldump.sql.gz && chmod 600 ${mysql::server::backup_dir}/mysqldump.sql.gz", user => 'root', minute => 0, diff --git a/manifests/server/cron/optimize.pp b/manifests/server/cron/optimize.pp index 5d4fa98..887906d 100644 --- a/manifests/server/cron/optimize.pp +++ b/manifests/server/cron/optimize.pp @@ -2,18 +2,21 @@ class mysql::server::cron::optimize ( $optimize_hour, $optimize_minute, - $optimize_day + $optimize_day, + $ensure = present, ) { file { 'mysql_optimize_script': - path => '/usr/local/sbin/optimize_mysql_tables.rb', - source => 'puppet:///modules/mysql/scripts/optimize_tables.rb', - owner => root, - group => 0, - mode => '0700'; + ensure => $ensure, + path => '/usr/local/sbin/optimize_mysql_tables.rb', + source => 'puppet:///modules/mysql/scripts/optimize_tables.rb', + owner => root, + group => 0, + mode => '0700'; } cron { 'mysql_optimize_cron': + ensure => $ensure, command => '/usr/local/sbin/optimize_mysql_tables.rb', user => 'root', minute => $optimize_minute, -- cgit v1.2.3