From ae2fbce7ac58d2f6bb33b350aee6482fd5a94df7 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Thu, 6 Mar 2014 18:38:20 -0500 Subject: Randomize time of execution for optimize script. By default, time will be between midnight and 7:00 any day of the week. The values are currently hard-coded. This can have serious I/O repercussions on a server with multiple VMs that run mysql since they will all run their optimizations simultaneously. --- manifests/server.pp | 3 +++ manifests/server/base.pp | 6 +++++- manifests/server/cron/optimize.pp | 12 ++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/manifests/server.pp b/manifests/server.pp index a03dd7b..bfcdf69 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -8,6 +8,9 @@ class mysql::server ( $nagios_password_hash = 'absent', $backup_cron = false, $optimize_cron = false, + $optimize_hour = fqdn_rand(7), + $optimize_minute = fqdn_rand(60), + $optimize_day = fqdn_rand(7), $backup_dir = '/var/backups/mysql', $manage_backup_dir = true, $nagios_notcp = false diff --git a/manifests/server/base.pp b/manifests/server/base.pp index 14f3c1b..b379f5c 100644 --- a/manifests/server/base.pp +++ b/manifests/server/base.pp @@ -70,7 +70,11 @@ class mysql::server::base { } if $mysql::server::optimize_cron { - include mysql::server::cron::optimize + class { 'mysql::server::cron::optimize': + 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/optimize.pp b/manifests/server/cron/optimize.pp index d1d0257..5d4fa98 100644 --- a/manifests/server/cron/optimize.pp +++ b/manifests/server/cron/optimize.pp @@ -1,5 +1,9 @@ # optimize mysql databases regurarely -class mysql::server::cron::optimize { +class mysql::server::cron::optimize ( + $optimize_hour, + $optimize_minute, + $optimize_day +) { file { 'mysql_optimize_script': path => '/usr/local/sbin/optimize_mysql_tables.rb', @@ -12,9 +16,9 @@ class mysql::server::cron::optimize { cron { 'mysql_optimize_cron': command => '/usr/local/sbin/optimize_mysql_tables.rb', user => 'root', - minute => 40, - hour => 6, - weekday => 7, + minute => $optimize_minute, + hour => $optimize_hour, + weekday => $optimize_day, require => [ Exec['mysql_set_rootpw'], File['mysql_root_cnf'], File['mysql_optimize_script'] ], -- cgit v1.2.3 From a5754aa8025d75fd1bb55e210ec90ede7b563c10 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Thu, 6 Mar 2014 18:52:57 -0500 Subject: document the new arguments for setting optimize run time --- README | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README b/README index a454dbd..1b12c76 100644 --- a/README +++ b/README @@ -61,6 +61,16 @@ Optimizing tables If you wish mysql to periodically optimize tables, set the "$mysql_optimize_cron = true" variable before you include mysql::server. +By default, time of execution for the optimization script will be randomly +chosen (and will stay consistant for a server) any day between midnight and +7:00 AM. If you wish to force at least one value, you can use the following +parameters to the mysql::server class (all values are used directly as a +cronjob value so they should be set within cron value space): + +* optimize_day => sets the day of the week (integer value) during which the script will run. +* optimize_hour => sets the hour at which the optimization script will run. +* optimize_minute => sets the minute in the hour at which the script will run. + Munin ----- -- cgit v1.2.3