mysql: Enable deployer to set Limits
This commits aims to enable a deployer to override unit default
parameters, including limits (LimitNOFILE, etc...), TimeoutSec
and more.
Closes-Bug: 1410863
Change-Id: If712d35fa2ac6a530e6da923b610e33eae11208b
(cherry picked from commit c3220b9d2d)
			
			
This commit is contained in:
		
				
					committed by
					
						
						Cédric LECOMTE
					
				
			
			
				
	
			
			
			
						parent
						
							55b0d4d3f1
						
					
				
				
					commit
					5f6fa04b1d
				
			@@ -169,54 +169,73 @@
 | 
			
		||||
#   (optional) The name or ip address of host running monitoring database (clustercheck)
 | 
			
		||||
#   Defaults to '127.0.0.1'
 | 
			
		||||
#
 | 
			
		||||
# [*open_files_limit*]
 | 
			
		||||
#   (optional) An integer that specifies the open_files_limit for MySQL
 | 
			
		||||
#   Defaults to 65535
 | 
			
		||||
#
 | 
			
		||||
# [*mysql_systemd_override_settings*]
 | 
			
		||||
#   (optional) An hash of setting to override for MariaDB unit file.
 | 
			
		||||
#   Defaults to {}
 | 
			
		||||
#   Example : { 'LimitNOFILE' => 'infinity', 'LimitNPROC' => 4, 'TimeoutSec' => '30' }
 | 
			
		||||
#
 | 
			
		||||
# [*firewall_settings*]
 | 
			
		||||
#   (optional) Allow to add custom parameters to firewall rules
 | 
			
		||||
#   Should be an hash.
 | 
			
		||||
#   Default to {}
 | 
			
		||||
#
 | 
			
		||||
class cloud::database::sql::mysql (
 | 
			
		||||
    $api_eth                        = '127.0.0.1',
 | 
			
		||||
    $galera_master_name             = 'mgmt001',
 | 
			
		||||
    $galera_internal_ips            = ['127.0.0.1'],
 | 
			
		||||
    $galera_gcache                  = '1G',
 | 
			
		||||
    $keystone_db_host               = '127.0.0.1',
 | 
			
		||||
    $keystone_db_user               = 'keystone',
 | 
			
		||||
    $keystone_db_password           = 'keystonepassword',
 | 
			
		||||
    $keystone_db_allowed_hosts      = ['127.0.0.1'],
 | 
			
		||||
    $cinder_db_host                 = '127.0.0.1',
 | 
			
		||||
    $cinder_db_user                 = 'cinder',
 | 
			
		||||
    $cinder_db_password             = 'cinderpassword',
 | 
			
		||||
    $cinder_db_allowed_hosts        = ['127.0.0.1'],
 | 
			
		||||
    $glance_db_host                 = '127.0.0.1',
 | 
			
		||||
    $glance_db_user                 = 'glance',
 | 
			
		||||
    $glance_db_password             = 'glancepassword',
 | 
			
		||||
    $glance_db_allowed_hosts        = ['127.0.0.1'],
 | 
			
		||||
    $heat_db_host                   = '127.0.0.1',
 | 
			
		||||
    $heat_db_user                   = 'heat',
 | 
			
		||||
    $heat_db_password               = 'heatpassword',
 | 
			
		||||
    $heat_db_allowed_hosts          = ['127.0.0.1'],
 | 
			
		||||
    $nova_db_host                   = '127.0.0.1',
 | 
			
		||||
    $nova_db_user                   = 'nova',
 | 
			
		||||
    $nova_db_password               = 'novapassword',
 | 
			
		||||
    $nova_db_allowed_hosts          = ['127.0.0.1'],
 | 
			
		||||
    $neutron_db_host                = '127.0.0.1',
 | 
			
		||||
    $neutron_db_user                = 'neutron',
 | 
			
		||||
    $neutron_db_password            = 'neutronpassword',
 | 
			
		||||
    $neutron_db_allowed_hosts       = ['127.0.0.1'],
 | 
			
		||||
    $trove_db_host                  = '127.0.0.1',
 | 
			
		||||
    $trove_db_user                  = 'trove',
 | 
			
		||||
    $trove_db_password              = 'trovepassword',
 | 
			
		||||
    $trove_db_allowed_hosts         = ['127.0.0.1'],
 | 
			
		||||
    $mysql_root_password            = 'rootpassword',
 | 
			
		||||
    $mysql_sys_maint_password       = 'sys_maint',
 | 
			
		||||
    $galera_clustercheck_dbuser     = 'clustercheckdbuser',
 | 
			
		||||
    $galera_clustercheck_dbpassword = 'clustercheckpassword',
 | 
			
		||||
    $galera_clustercheck_ipaddress  = '127.0.0.1',
 | 
			
		||||
    $firewall_settings              = {},
 | 
			
		||||
    $api_eth                         = '127.0.0.1',
 | 
			
		||||
    $galera_master_name              = 'mgmt001',
 | 
			
		||||
    $galera_internal_ips             = ['127.0.0.1'],
 | 
			
		||||
    $galera_gcache                   = '1G',
 | 
			
		||||
    $keystone_db_host                = '127.0.0.1',
 | 
			
		||||
    $keystone_db_user                = 'keystone',
 | 
			
		||||
    $keystone_db_password            = 'keystonepassword',
 | 
			
		||||
    $keystone_db_allowed_hosts       = ['127.0.0.1'],
 | 
			
		||||
    $cinder_db_host                  = '127.0.0.1',
 | 
			
		||||
    $cinder_db_user                  = 'cinder',
 | 
			
		||||
    $cinder_db_password              = 'cinderpassword',
 | 
			
		||||
    $cinder_db_allowed_hosts         = ['127.0.0.1'],
 | 
			
		||||
    $glance_db_host                  = '127.0.0.1',
 | 
			
		||||
    $glance_db_user                  = 'glance',
 | 
			
		||||
    $glance_db_password              = 'glancepassword',
 | 
			
		||||
    $glance_db_allowed_hosts         = ['127.0.0.1'],
 | 
			
		||||
    $heat_db_host                    = '127.0.0.1',
 | 
			
		||||
    $heat_db_user                    = 'heat',
 | 
			
		||||
    $heat_db_password                = 'heatpassword',
 | 
			
		||||
    $heat_db_allowed_hosts           = ['127.0.0.1'],
 | 
			
		||||
    $nova_db_host                    = '127.0.0.1',
 | 
			
		||||
    $nova_db_user                    = 'nova',
 | 
			
		||||
    $nova_db_password                = 'novapassword',
 | 
			
		||||
    $nova_db_allowed_hosts           = ['127.0.0.1'],
 | 
			
		||||
    $neutron_db_host                 = '127.0.0.1',
 | 
			
		||||
    $neutron_db_user                 = 'neutron',
 | 
			
		||||
    $neutron_db_password             = 'neutronpassword',
 | 
			
		||||
    $neutron_db_allowed_hosts        = ['127.0.0.1'],
 | 
			
		||||
    $trove_db_host                   = '127.0.0.1',
 | 
			
		||||
    $trove_db_user                   = 'trove',
 | 
			
		||||
    $trove_db_password               = 'trovepassword',
 | 
			
		||||
    $trove_db_allowed_hosts          = ['127.0.0.1'],
 | 
			
		||||
    $mysql_root_password             = 'rootpassword',
 | 
			
		||||
    $mysql_sys_maint_password        = 'sys_maint',
 | 
			
		||||
    $galera_clustercheck_dbuser      = 'clustercheckdbuser',
 | 
			
		||||
    $galera_clustercheck_dbpassword  = 'clustercheckpassword',
 | 
			
		||||
    $galera_clustercheck_ipaddress   = '127.0.0.1',
 | 
			
		||||
    $open_files_limit                = 65535,
 | 
			
		||||
    $mysql_systemd_override_settings = {},
 | 
			
		||||
    $firewall_settings               = {},
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
  include 'xinetd'
 | 
			
		||||
 | 
			
		||||
  if $mysql_systemd_override_settings['LimitNOFILE'] {
 | 
			
		||||
    $open_files_limit_real = $mysql_systemd_override_settings['LimitNOFILE']
 | 
			
		||||
    $mysql_systemd_override_settings_real = $mysql_systemd_override_settings
 | 
			
		||||
  } else {
 | 
			
		||||
    $open_files_limit_real = $open_files_limit
 | 
			
		||||
    $mysql_systemd_override_settings_real = merge($mysql_systemd_override_settings, { 'LimitNOFILE' => $open_files_limit})
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $gcomm_definition = inline_template('<%= @galera_internal_ips.join(",") + "?pc.wait_prim=no" -%>')
 | 
			
		||||
 | 
			
		||||
  # Specific to the Galera master node
 | 
			
		||||
@@ -349,6 +368,24 @@ class cloud::database::sql::mysql (
 | 
			
		||||
        require => [Package[$mysql_server_package_name], File[$mysql_server_config_file]]
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if $::operatingsystemrelease >= 7 {
 | 
			
		||||
        file { "/etc/systemd/system/${mysql_service_name}.service.d" :
 | 
			
		||||
          ensure => directory,
 | 
			
		||||
        }
 | 
			
		||||
        file { "/etc/systemd/system/${mysql_service_name}.service.d/custom.conf" :
 | 
			
		||||
          content => template('cloud/database/systemd-custom.conf.erb'),
 | 
			
		||||
          owner   => 'root',
 | 
			
		||||
          mode    => '0755',
 | 
			
		||||
          group   => 'root',
 | 
			
		||||
          notify  => [Service['mysqld'], Exec['mariadb-sysctl-daemon-reload']],
 | 
			
		||||
        }
 | 
			
		||||
        exec { 'mariadb-sysctl-daemon-reload' :
 | 
			
		||||
          command     => '/usr/bin/systemctl daemon-reload',
 | 
			
		||||
          refreshonly => true,
 | 
			
		||||
          notify      => Service['mysqld'],
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
    } # RedHat
 | 
			
		||||
    'Debian': {
 | 
			
		||||
      # Specific to Debian / Ubuntu
 | 
			
		||||
@@ -406,7 +443,7 @@ class cloud::database::sql::mysql (
 | 
			
		||||
    before  => Package[$mysql_server_package_name],
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if($::osfamily == 'Debian'){
 | 
			
		||||
  if $::osfamily == 'Debian' {
 | 
			
		||||
    # The startup time can be longer than the default 30s so we take
 | 
			
		||||
    # care of it there.  Until this bug is not resolved
 | 
			
		||||
    # https://mariadb.atlassian.net/browse/MDEV-5540, we have to do it
 | 
			
		||||
 
 | 
			
		||||
@@ -94,6 +94,34 @@ describe 'cloud::database::sql::mysql' do
 | 
			
		||||
 | 
			
		||||
    end # configure mysqlchk http replication
 | 
			
		||||
 | 
			
		||||
    context 'configure override of systemd defaults' do
 | 
			
		||||
      before :each do
 | 
			
		||||
        facts.merge!( :hostname => 'os-ci-test1',
 | 
			
		||||
                      :osfamily => 'RedHat',
 | 
			
		||||
                      :operatingsystemrelease => 7 )
 | 
			
		||||
      end
 | 
			
		||||
      before :each do
 | 
			
		||||
        params.merge!(:mysql_systemd_override_settings => { 'LimitNOFILE' => 666 })
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it { is_expected.to contain_file('/etc/systemd/system/mysql-bootstrap.service.d/custom.conf').with_content(/[Service]/) }
 | 
			
		||||
      it { is_expected.to contain_file('/etc/systemd/system/mysql-bootstrap.service.d/custom.conf').with_content(/LimitNOFILE=666/) }
 | 
			
		||||
      it { is_expected.to contain_file('/etc/my.cnf').with_content(/open_files_limit                = 666/) }
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'configure open_file_limits' do
 | 
			
		||||
      before :each do
 | 
			
		||||
        facts.merge!( :hostname => 'os-ci-test1',
 | 
			
		||||
                      :osfamily => 'RedHat',
 | 
			
		||||
                      :operatingsystemrelease => 7 )
 | 
			
		||||
      end
 | 
			
		||||
      before :each do
 | 
			
		||||
        params.merge!(:open_files_limit => 666)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it { is_expected.to contain_file('/etc/my.cnf').with_content(/open_files_limit                = 666/) }
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'configure databases on the galera master server' do
 | 
			
		||||
 | 
			
		||||
      before :each do
 | 
			
		||||
@@ -271,7 +299,8 @@ describe 'cloud::database::sql::mysql' do
 | 
			
		||||
 | 
			
		||||
  context 'on RedHat platforms' do
 | 
			
		||||
    let :facts do
 | 
			
		||||
      { :osfamily => 'RedHat' }
 | 
			
		||||
      { :osfamily => 'RedHat',
 | 
			
		||||
        :operatingsystemrelease => 7 }
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    let :platform_params do
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@ max_heap_table_size             = 128M
 | 
			
		||||
query_cache_type                = 0
 | 
			
		||||
myisam_recover                  = BACKUP
 | 
			
		||||
key_buffer_size                 = 16M
 | 
			
		||||
open_files_limit                = 65535
 | 
			
		||||
open_files_limit                = <%= @open_files_limit_real %>
 | 
			
		||||
table_open_cache                = 1024
 | 
			
		||||
table_definition_cache          = 500
 | 
			
		||||
myisam_sort_buffer_size         = 512M
 | 
			
		||||
@@ -37,7 +37,7 @@ innodb_flush_log_at_trx_commit  = 1
 | 
			
		||||
innodb_lock_wait_timeout        = 50
 | 
			
		||||
innodb_thread_concurrency       = 48
 | 
			
		||||
innodb_file_per_table           = 1
 | 
			
		||||
innodb_open_files               = 65535
 | 
			
		||||
innodb_open_files               = <%= @open_files_limit_real %>
 | 
			
		||||
innodb_io_capacity              = 1000
 | 
			
		||||
innodb_file_format              = Barracuda
 | 
			
		||||
innodb_file_format_max          = Barracuda
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								templates/database/systemd-custom.conf.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								templates/database/systemd-custom.conf.erb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
[Service]
 | 
			
		||||
<% @mysql_systemd_override_settings_real.each do |key, value| -%>
 | 
			
		||||
<%= key -%>=<%= value %>
 | 
			
		||||
<% end -%>
 | 
			
		||||
		Reference in New Issue
	
	Block a user