Skip to content

Commit 5bdf86f

Browse files
authored
Merge pull request #60 from MaxFedotov/configs_separation
add ability to split config into 2 files
2 parents 024713a + 0b75147 commit 5bdf86f

File tree

11 files changed

+129
-19
lines changed

11 files changed

+129
-19
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Matthias Crauwels (@mcrauwel)
44
Narcis Pillao (@narcisbcn)
55
Rudy Gevaert (@rgevaert)
66
Tim Meusel (@bastelfreak)
7+
Maxim Fedotov (@MaxFedotov)

README.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ Array of mysql_rules, that will be created in ProxySQL. Defaults to undef
321321

322322
##### `schedulers`
323323
Array of schedulers, that will be created in ProxySQL. Defaults to undef
324+
##### `split_config`
325+
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
326+
327+
##### `proxy_config_file`
328+
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'
329+
330+
#####`manage_proxy_config_file`
331+
Determines wheter this module will update the ProxySQL proxy configuration file. Defaults to 'true'
324332

325333
## Types
326334
#### proxy_global_variable

manifests/config.pp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
class proxysql::config {
66

77
$config_settings = $proxysql::config_settings
8+
$proxy_config_file = $proxysql::proxy_config_file
9+
$split_config = $proxysql::split_config
10+
811
if $proxysql::manage_config_file {
912
file { 'proxysql-config-file':
1013
ensure => file,
@@ -17,4 +20,16 @@
1720
}
1821
}
1922

23+
if $proxysql::split_config {
24+
file { 'proxysql-proxy-config-file':
25+
ensure => file,
26+
path => $proxysql::proxy_config_file,
27+
content => epp('proxysql/proxysql_proxy.cnf.epp', { config_settings => $config_settings }),
28+
mode => '0640',
29+
owner => $proxysql::sys_owner,
30+
group => $proxysql::sys_group,
31+
selinux_ignore_defaults => true,
32+
replace => $proxysql::manage_proxy_config_file,
33+
}
34+
}
2035
}

manifests/init.pp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
# Which configuration variables should be overriden. Hash, defaults to {} (empty hash).
103103
#
104104
# * `cluster_name`
105-
# If set, proxysql_servers with the same cluster_name will be automatically added to the same cluster and will
105+
# If set, proxysql_servers with the same cluster_name will be automatically added to the same cluster and will
106106
# synchronize their configuration parameters. Defaults to undef
107107
#
108108
# * `cluster_username`
@@ -116,7 +116,7 @@
116116
# The name of the mysql client package in your package manager. Defaults to undef
117117
#
118118
# * `manage_hostgroup_for_servers`
119-
# Determines wheter this module will manage hostgroup_id for mysql_servers.
119+
# Determines wheter this module will manage hostgroup_id for mysql_servers.
120120
# If false - it will skip difference in this value between manifest and defined in ProxySQL. Defaults to 'true'
121121
#
122122
# * `mysql_servers`
@@ -133,6 +133,16 @@
133133
#
134134
# * `schedulers`
135135
# Array of schedulers, that will be created in ProxySQL. Defaults to undef
136+
# * `split_config`
137+
# If set, ProxySQL config file will be split in 2: main config file with admin and mysql variables
138+
# and proxy config file with servers\users\hostgroups\scheduler params. Defaults to false
139+
#
140+
# * `proxy_config_file`
141+
# The file where servers\users\hostgroups\scheduler\rules params of ProxySQL configuration are saved
142+
# This will only be configured if `split_config` is set to `true`. Defaults to 'proxysql_proxy.cnf'
143+
#
144+
# * `manage_proxy_config_file`
145+
# Determines wheter this module will update the ProxySQL proxy configuration file. Defaults to 'true'
136146
#
137147
class proxysql (
138148
Optional[String] $cluster_name = $proxysql::params::cluster_name,
@@ -158,6 +168,11 @@
158168
String $monitor_username = $proxysql::params::monitor_username,
159169
Sensitive[String] $monitor_password = $proxysql::params::monitor_password,
160170

171+
Boolean $split_config = $proxysql::params::split_config,
172+
173+
String $proxy_config_file = $proxysql::params::proxy_config_file,
174+
Boolean $manage_proxy_config_file = $proxysql::params::manage_proxy_config_file,
175+
161176
String $config_file = $proxysql::params::config_file,
162177
Boolean $manage_config_file = $proxysql::params::manage_config_file,
163178

@@ -227,11 +242,13 @@
227242
# lint:endignore
228243

229244
anchor { 'proxysql::begin': }
245+
-> class { 'proxysql::prerequisites':}
230246
-> class { 'proxysql::repo':}
231247
-> class { 'proxysql::install':}
232248
-> class { 'proxysql::config':}
233249
-> class { 'proxysql::service':}
234250
-> class { 'proxysql::admin_credentials':}
251+
-> class { 'proxysql::reload_config':}
235252
-> class { 'proxysql::configure':}
236253
-> anchor { 'proxysql::end': }
237254

manifests/install.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
}
3636
}
3737

38+
3839
file { 'proxysql-datadir':
3940
ensure => directory,
4041
path => $proxysql::datadir,

manifests/params.pp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
'Debian': {
3333
case $facts['os']['release']['major'] {
3434
'8': {
35-
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-debian8_amd64.deb'
36-
$package_checksum_value = '98bab1b7cd719039b1483f7d51c30d7fc563def7'
35+
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-debian8_amd64.deb'
36+
$package_checksum_value = '813a91ea030ef480c0210b047df5e88ff1c27810'
3737
$package_checksum_type = 'sha1'
3838
$package_dependencies = []
3939
}
4040
'9': {
41-
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-debian9_amd64.deb'
42-
$package_checksum_value = 'd97a2f870e46d5f3218ab80d6c0db6bcc288127a'
41+
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-debian9_amd64.deb'
42+
$package_checksum_value = '65a3c2b98eefa42946ee59eef18ba18534c2a39d'
4343
$package_checksum_type = 'sha1'
4444
$package_dependencies = []
4545
}
@@ -54,14 +54,14 @@
5454
'Ubuntu': {
5555
case $facts['os']['release']['major'] {
5656
'14.04': {
57-
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-ubuntu14_amd64.deb'
58-
$package_checksum_value = '0b89f290bd9cd7e8bc2b7acd8a7799840a31af94'
57+
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-ubuntu14_amd64.deb'
58+
$package_checksum_value = '42b99a12e8e43410aed88da4c5bbe902c43dbba1'
5959
$package_checksum_type = 'sha1'
6060
$package_dependencies = []
6161
}
6262
'16.04': {
63-
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql_1.4.10-ubuntu16_amd64.deb'
64-
$package_checksum_value = 'df8695c6296678a0eeda036cddff679cc1ff604e'
63+
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql_1.4.11-ubuntu16_amd64.deb'
64+
$package_checksum_value = '6e7db2fee78eee1a22cdfabefaa50953c3d24501'
6565
$package_checksum_type = 'sha1'
6666
$package_dependencies = []
6767
}
@@ -95,8 +95,8 @@
9595
}
9696
'RedHat': {
9797
$package_provider = 'rpm'
98-
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.10/proxysql-1.4.10-1-centos67.x86_64.rpm'
99-
$package_checksum_value = 'f5ca4efa9d69e9bd6ba9a96c724b031cd7326051'
98+
$package_source = 'https://github.com/sysown/proxysql/releases/download/v1.4.11/proxysql-1.4.11-1-centos67.x86_64.rpm'
99+
$package_checksum_value = '6f302beaea096b63851a136287818a1b6e049e28'
100100
$package_checksum_type = 'sha1'
101101
$package_dependencies = ['perl-DBI', 'perl-DBD-mysql']
102102
$repo = {
@@ -117,8 +117,11 @@
117117

118118
$datadir = '/var/lib/proxysql'
119119

120-
$config_file = '/etc/proxysql.cnf'
121-
$manage_config_file = true
120+
$split_config = false
121+
$config_file = '/etc/proxysql.cnf'
122+
$manage_config_file = true
123+
$proxy_config_file = '/etc/proxysql_proxy.cnf'
124+
$manage_proxy_config_file = true
122125

123126
$mycnf_file_name = '/root/.my.cnf'
124127
$manage_mycnf_file = true

manifests/prerequisites.pp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Class: proxysql::prerequisites
2+
# ===========================
3+
#
4+
# Manage the prerequisites where the ProxySQL package might be
5+
#
6+
class proxysql::prerequisites inherits proxysql {
7+
if $proxysql::sys_owner != 'root' { # let's assume that 'root' will exist and not touch that...
8+
group { $proxysql::sys_group:
9+
ensure => 'present',
10+
}
11+
12+
user { $proxysql::sys_owner:
13+
ensure => 'present',
14+
groups => $proxysql::sys_group,
15+
}
16+
}
17+
18+
}

manifests/reload_config.pp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# == Class proxysql::reload_config
2+
#
3+
# This class is called from proxysql to update config if it changed.
4+
#
5+
class proxysql::reload_config {
6+
7+
$subscribe = $proxysql::split_config ? {
8+
true => [ File['proxysql-config-file'], File['proxysql-proxy-config-file'] ],
9+
false => File['proxysql-config-file'],
10+
}
11+
12+
$mycnf_file_name = $proxysql::mycnf_file_name
13+
exec {'reload-config':
14+
command => "/usr/bin/mysql --defaults-extra-file=${mycnf_file_name} --execute=\"
15+
LOAD ADMIN VARIABLES FROM CONFIG; \
16+
LOAD ADMIN VARIABLES TO RUNTIME; \
17+
SAVE ADMIN VARIABLES TO DISK; \
18+
LOAD MYSQL VARIABLES FROM CONFIG; \
19+
LOAD MYSQL VARIABLES TO RUNTIME; \
20+
SAVE MYSQL VARIABLES TO DISK; \"
21+
",
22+
subscribe => $subscribe,
23+
require => [ Service[$proxysql::service_name] , File['root-mycnf-file'] ],
24+
refreshonly => true,
25+
}
26+
}

spec/classes/proxysql_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
it { is_expected.to contain_class('proxysql::install').that_comes_before('Class[proxysql::config]') }
1919
it { is_expected.to contain_class('proxysql::config').that_comes_before('Class[proxysql::service]') }
2020
it { is_expected.to contain_class('proxysql::service').that_comes_before('Class[proxysql::admin_credentials]') }
21-
it { is_expected.to contain_class('proxysql::admin_credentials').that_comes_before('Class[proxysql::configure]') }
21+
it { is_expected.to contain_class('proxysql::admin_credentials').that_comes_before('Class[proxysql::reload_config]') }
22+
it { is_expected.to contain_class('proxysql::reload_config').that_comes_before('Class[proxysql::configure]') }
2223
it { is_expected.to contain_class('proxysql::configure').that_comes_before('Anchor[proxysql::end]') }
2324

2425
it { is_expected.to contain_anchor('proxysql::end') }

templates/proxysql.cnf.erb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ default_handler = Proc.new do |k, v|
1212
<%
1313
end
1414
end
15-
1615
hash_handler = Proc.new do |k, v|
1716
if v.is_a?(Hash)
1817
-%>
@@ -27,7 +26,6 @@ hash_handler = Proc.new do |k, v|
2726
default_handler.call(k, v)
2827
end
2928
end
30-
3129
@config_settings.map do |k, v|
3230
if v.is_a?(Hash)
3331
if k == 'admin_variables' || k == 'mysql_variables'
@@ -42,6 +40,7 @@ end
4240
<%
4341
else
4442
-%>
43+
<% if @split_config == false -%>
4544
<%= k %> = (
4645
<%
4746
v.each do |ki, vi|
@@ -50,7 +49,6 @@ end
5049
else
5150
default_handler.call(ki, vi)
5251
end
53-
5452
if v.keys.index(ki) < v.size - 1
5553
-%>
5654
,
@@ -60,11 +58,15 @@ end
6058
-%>
6159

6260
)
63-
61+
<% end -%>
6462
<%
6563
end
6664
else
6765
default_handler.call(k, v)
6866
end
6967
end
7068
-%>
69+
70+
<% if @split_config == true -%>
71+
@include "<%= @proxy_config_file %>"
72+
<% end -%>

0 commit comments

Comments
 (0)