diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e59b824a..4c35044f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -4,3 +4,4 @@ Matthias Crauwels (@mcrauwel) Narcis Pillao (@narcisbcn) Rudy Gevaert (@rgevaert) Tim Meusel (@bastelfreak) +Maxim Fedotov (@MaxFedotov) \ No newline at end of file diff --git a/README.markdown b/README.markdown index 31c11df2..250b0d90 100644 --- a/README.markdown +++ b/README.markdown @@ -321,6 +321,14 @@ Array of mysql_rules, that will be created in ProxySQL. Defaults to undef ##### `schedulers` Array of schedulers, that will be created in ProxySQL. Defaults to undef +##### `split_config` +If set, ProxySQL config file will be split in 2: main config file with admin and mysql variables and proxy config file with servers\users\hostgroups\scheduler\rules params. Defaults to false + +##### `proxy_config_file` +The file where servers\users\hostgroups\scheduler\rules params of ProxySQL configuration are saved. This will only be configured if `split_config` is set to `true`. Defaults to 'proxysql_proxy.cnf' + +#####`manage_proxy_config_file` +Determines wheter this module will update the ProxySQL proxy configuration file. Defaults to 'true' ## Types #### proxy_global_variable diff --git a/manifests/config.pp b/manifests/config.pp index 11607ba1..22a9fbc6 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -5,6 +5,9 @@ class proxysql::config { $config_settings = $proxysql::config_settings + $proxy_config_file = $proxysql::proxy_config_file + $split_config = $proxysql::split_config + if $proxysql::manage_config_file { file { 'proxysql-config-file': ensure => file, @@ -17,4 +20,16 @@ } } + if $proxysql::split_config { + file { 'proxysql-proxy-config-file': + ensure => file, + path => $proxysql::proxy_config_file, + content => epp('proxysql/proxysql_proxy.cnf.epp', { config_settings => $config_settings }), + mode => '0640', + owner => $proxysql::sys_owner, + group => $proxysql::sys_group, + selinux_ignore_defaults => true, + replace => $proxysql::manage_proxy_config_file, + } + } } diff --git a/manifests/init.pp b/manifests/init.pp index 6d0eccf8..3d228f7a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -102,7 +102,7 @@ # Which configuration variables should be overriden. Hash, defaults to {} (empty hash). # # * `cluster_name` -# If set, proxysql_servers with the same cluster_name will be automatically added to the same cluster and will +# If set, proxysql_servers with the same cluster_name will be automatically added to the same cluster and will # synchronize their configuration parameters. Defaults to undef # # * `cluster_username` @@ -116,7 +116,7 @@ # The name of the mysql client package in your package manager. Defaults to undef # # * `manage_hostgroup_for_servers` -# Determines wheter this module will manage hostgroup_id for mysql_servers. +# Determines wheter this module will manage hostgroup_id for mysql_servers. # If false - it will skip difference in this value between manifest and defined in ProxySQL. Defaults to 'true' # # * `mysql_servers` @@ -133,6 +133,16 @@ # # * `schedulers` # Array of schedulers, that will be created in ProxySQL. Defaults to undef +# * `split_config` +# If set, ProxySQL config file will be split in 2: main config file with admin and mysql variables +# and proxy config file with servers\users\hostgroups\scheduler params. Defaults to false +# +# * `proxy_config_file` +# The file where servers\users\hostgroups\scheduler\rules params of ProxySQL configuration are saved +# This will only be configured if `split_config` is set to `true`. Defaults to 'proxysql_proxy.cnf' +# +# * `manage_proxy_config_file` +# Determines wheter this module will update the ProxySQL proxy configuration file. Defaults to 'true' # class proxysql ( Optional[String] $cluster_name = $proxysql::params::cluster_name, @@ -158,6 +168,11 @@ String $monitor_username = $proxysql::params::monitor_username, Sensitive[String] $monitor_password = $proxysql::params::monitor_password, + Boolean $split_config = $proxysql::params::split_config, + + String $proxy_config_file = $proxysql::params::proxy_config_file, + Boolean $manage_proxy_config_file = $proxysql::params::manage_proxy_config_file, + String $config_file = $proxysql::params::config_file, Boolean $manage_config_file = $proxysql::params::manage_config_file, @@ -227,11 +242,13 @@ # lint:endignore anchor { 'proxysql::begin': } + -> class { 'proxysql::prerequisites':} -> class { 'proxysql::repo':} -> class { 'proxysql::install':} -> class { 'proxysql::config':} -> class { 'proxysql::service':} -> class { 'proxysql::admin_credentials':} + -> class { 'proxysql::reload_config':} -> class { 'proxysql::configure':} -> anchor { 'proxysql::end': } diff --git a/manifests/install.pp b/manifests/install.pp index 2bc75e16..d10f2c75 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -35,6 +35,7 @@ } } + file { 'proxysql-datadir': ensure => directory, path => $proxysql::datadir, diff --git a/manifests/params.pp b/manifests/params.pp index 0bfa2714..763945e3 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -32,14 +32,14 @@ 'Debian': { case $facts['os']['release']['major'] { '8': { - $package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-debian8_amd64.deb' - $package_checksum_value = '98bab1b7cd719039b1483f7d51c30d7fc563def7' + $package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-debian8_amd64.deb' + $package_checksum_value = '813a91ea030ef480c0210b047df5e88ff1c27810' $package_checksum_type = 'sha1' $package_dependencies = [] } '9': { - $package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-debian9_amd64.deb' - $package_checksum_value = 'd97a2f870e46d5f3218ab80d6c0db6bcc288127a' + $package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-debian9_amd64.deb' + $package_checksum_value = '65a3c2b98eefa42946ee59eef18ba18534c2a39d' $package_checksum_type = 'sha1' $package_dependencies = [] } @@ -54,14 +54,14 @@ 'Ubuntu': { case $facts['os']['release']['major'] { '14.04': { - $package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-ubuntu14_amd64.deb' - $package_checksum_value = '0b89f290bd9cd7e8bc2b7acd8a7799840a31af94' + $package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-ubuntu14_amd64.deb' + $package_checksum_value = '42b99a12e8e43410aed88da4c5bbe902c43dbba1' $package_checksum_type = 'sha1' $package_dependencies = [] } '16.04': { - $package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-ubuntu16_amd64.deb' - $package_checksum_value = 'df8695c6296678a0eeda036cddff679cc1ff604e' + $package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-ubuntu16_amd64.deb' + $package_checksum_value = '6e7db2fee78eee1a22cdfabefaa50953c3d24501' $package_checksum_type = 'sha1' $package_dependencies = [] } @@ -95,8 +95,8 @@ } 'RedHat': { $package_provider = 'rpm' - $package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql-1.4.10-1-centos67.x86_64.rpm' - $package_checksum_value = 'f5ca4efa9d69e9bd6ba9a96c724b031cd7326051' + $package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql-1.4.11-1-centos67.x86_64.rpm' + $package_checksum_value = '6f302beaea096b63851a136287818a1b6e049e28' $package_checksum_type = 'sha1' $package_dependencies = ['perl-DBI', 'perl-DBD-mysql'] $repo = { @@ -117,8 +117,11 @@ $datadir = '/var/lib/proxysql' - $config_file = '/etc/proxysql.cnf' - $manage_config_file = true + $split_config = false + $config_file = '/etc/proxysql.cnf' + $manage_config_file = true + $proxy_config_file = '/etc/proxysql_proxy.cnf' + $manage_proxy_config_file = true $mycnf_file_name = '/root/.my.cnf' $manage_mycnf_file = true diff --git a/manifests/prerequisites.pp b/manifests/prerequisites.pp new file mode 100644 index 00000000..c98ebda3 --- /dev/null +++ b/manifests/prerequisites.pp @@ -0,0 +1,18 @@ +# Class: proxysql::prerequisites +# =========================== +# +# Manage the prerequisites where the ProxySQL package might be +# +class proxysql::prerequisites inherits proxysql { + if $proxysql::sys_owner != 'root' { # let's assume that 'root' will exist and not touch that... + group { $proxysql::sys_group: + ensure => 'present', + } + + user { $proxysql::sys_owner: + ensure => 'present', + groups => $proxysql::sys_group, + } + } + +} diff --git a/manifests/reload_config.pp b/manifests/reload_config.pp new file mode 100644 index 00000000..578b793a --- /dev/null +++ b/manifests/reload_config.pp @@ -0,0 +1,26 @@ +# == Class proxysql::reload_config +# +# This class is called from proxysql to update config if it changed. +# +class proxysql::reload_config { + + $subscribe = $proxysql::split_config ? { + true => [ File['proxysql-config-file'], File['proxysql-proxy-config-file'] ], + false => File['proxysql-config-file'], + } + + $mycnf_file_name = $proxysql::mycnf_file_name + exec {'reload-config': + command => "/usr/bin/mysql --defaults-extra-file=${mycnf_file_name} --execute=\" + LOAD ADMIN VARIABLES FROM CONFIG; \ + LOAD ADMIN VARIABLES TO RUNTIME; \ + SAVE ADMIN VARIABLES TO DISK; \ + LOAD MYSQL VARIABLES FROM CONFIG; \ + LOAD MYSQL VARIABLES TO RUNTIME; \ + SAVE MYSQL VARIABLES TO DISK; \" + ", + subscribe => $subscribe, + require => [ Service[$proxysql::service_name] , File['root-mycnf-file'] ], + refreshonly => true, + } +} diff --git a/spec/classes/proxysql_spec.rb b/spec/classes/proxysql_spec.rb index 8499ba8d..9f0fb90e 100644 --- a/spec/classes/proxysql_spec.rb +++ b/spec/classes/proxysql_spec.rb @@ -18,7 +18,8 @@ it { is_expected.to contain_class('proxysql::install').that_comes_before('Class[proxysql::config]') } it { is_expected.to contain_class('proxysql::config').that_comes_before('Class[proxysql::service]') } it { is_expected.to contain_class('proxysql::service').that_comes_before('Class[proxysql::admin_credentials]') } - it { is_expected.to contain_class('proxysql::admin_credentials').that_comes_before('Class[proxysql::configure]') } + it { is_expected.to contain_class('proxysql::admin_credentials').that_comes_before('Class[proxysql::reload_config]') } + it { is_expected.to contain_class('proxysql::reload_config').that_comes_before('Class[proxysql::configure]') } it { is_expected.to contain_class('proxysql::configure').that_comes_before('Anchor[proxysql::end]') } it { is_expected.to contain_anchor('proxysql::end') } diff --git a/templates/proxysql.cnf.erb b/templates/proxysql.cnf.erb index 60eaf374..bb946a32 100644 --- a/templates/proxysql.cnf.erb +++ b/templates/proxysql.cnf.erb @@ -12,7 +12,6 @@ default_handler = Proc.new do |k, v| <% end end - hash_handler = Proc.new do |k, v| if v.is_a?(Hash) -%> @@ -27,7 +26,6 @@ hash_handler = Proc.new do |k, v| default_handler.call(k, v) end end - @config_settings.map do |k, v| if v.is_a?(Hash) if k == 'admin_variables' || k == 'mysql_variables' @@ -42,6 +40,7 @@ end <% else -%> +<% if @split_config == false -%> <%= k %> = ( <% v.each do |ki, vi| @@ -50,7 +49,6 @@ end else default_handler.call(ki, vi) end - if v.keys.index(ki) < v.size - 1 -%> , @@ -60,7 +58,7 @@ end -%> ) - +<% end -%> <% end else @@ -68,3 +66,7 @@ end end end -%> + +<% if @split_config == true -%> +@include "<%= @proxy_config_file %>" +<% end -%> diff --git a/templates/proxysql_proxy.cnf.epp b/templates/proxysql_proxy.cnf.epp new file mode 100644 index 00000000..5297a5c5 --- /dev/null +++ b/templates/proxysql_proxy.cnf.epp @@ -0,0 +1,18 @@ +<%- | Hash $config_settings | -%> +<% $config_settings.each |$key, $value| { -%> +<% if $key == "mysql_servers" { -%> +<%= $key %> = (<% if $value != {} { -%><%= $value %><% } -%>) +<% } -%> +<% if $key == "mysql_users" { -%> +<%= $key %> = (<% if $value != {} { -%><%= $value %><% } -%>) +<% } -%> +<% if $key == "mysql_query_rules" { -%> +<%= $key %> = (<% if $value != {} { -%><%= $value %><% } -%>) +<% } -%> +<% if $key == "scheduler" { -%> +<%= $key %> = (<% if $value != {} { -%><%= $value %><% } -%>) +<% } -%> +<% if $key == "mysql_replication_hostgroups" { -%> +<%= $key %> = (<% if $value != {} { -%><%= $value %><% } -%>) +<% } -%> +<% } -%>