createdb for mysql8

This commit is contained in:
Tube 2023-10-22 23:29:39 +02:00
parent 17ca7a5299
commit ff692df2ee
1 changed files with 100 additions and 11 deletions

111
mysql.cf
View File

@ -14,20 +14,31 @@ vars:
"cfg" data => mergedata(@(default_cfg),@(cfg_param));
freebsd::
# "pkg" string => "mariadb106-server";
"pkg" slist => {"mysql80-server"};
# "server_pkgs" slist => {"mariadb106-server"};
# "client_pkgs" slist => {"mariadb106-client"};
"server_pkgs" slist => {"mysql80-server"};
"client_pkgs" slist => {"mysql80-client"};
"type" string => "mysql8";
"service_name" string => "mysql-server";
"cfg_dir" string => "/usr/local/etc/mysql";
"cfg_file" string => "/usr/local/etc/mysql/my.cnf";
"bin_dir" string => "/usr/local/bin";
debian::
"pkg" slist => {"mariadb-server"};
"server_pkgs" slist => {"mariadb-server"};
"client_pkgs" slist => {"mariadb-client"};
"type" string => "mariadb";
"service_name" string => "mysql";
"cfg_dir" string => "/etc/mysql";
"cfg_file" string => "/etc/mysql/my.cnf";
"bin_dir" string => "/usr/bin";
fedora::
"server_pkgs" slist => {"mariadb-server"};
"client_pkgs" slist => {"mariadb-client"};
"type" string => "mariadb";
"service_name" string => "mariadb";
"cfg_dir" string => "/etc/mysql";
"cfg_file" string => "/etc/my.cnf";
"bin_dir" string => "/usr/bin"; any::
any::
"mysql_cmd" string => "$(bin_dir)/mysql";
"mysqldump_cmd" string => "$(bin_dir)/mysqldump";
@ -56,10 +67,6 @@ files:
classes => if_repaired("mysql_repaired");
methods:
"any" usebundle => wmde_install_packages(@(mysql.pkg),"mysql"),
depends_on => { "mysql_cfg_created"};
services:
"$(service_name)"
depends_on => {"mysql_pkgs_installed"},
@ -74,7 +81,83 @@ services:
reports:
}
bundle agent install_mysql_server(cfg)
{
vars:
"mysqld_idx" slist => getindices(@(cfg[settings][mysqld]));
"settings[mysqld][$(mysqld_idx)]" string => "$(cfg[settings][mysqld][$(mysqld_idx)])";
"j" string => storejson(@(cfg));
methods:
"any" usebundle => wmde_install_packages(@(mysql.server_pkgs),"mysql_server");
files:
"$(mysql.cfg_file)"
copy_from => seed_cp("$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/my.cnf.mustache"),
handle => "myslq_server_cfg_created",
depends_on => {"mysql_server_pkgs_installed"};
"$(mysql.cfg_file)"
create => "true",
perms => m("644"),
edit_line => set_variable_values_inix("$(this.bundle).settings","mysqld"),
depends_on => {"myslq_server_cfg_created"},
handle => "myslq_server_cfg_edited",
classes => if_repaired("mysql_server_repaired");
methods:
"any" usebundle => wmde_service("$(mysql.service_name)","mysql_server_kept","mysql_server_repaired"),
depends_on => {"myslq_server_cfg_edited"};
reports:
}
bundle edit_line set_variable_values_inix(tab, sectionName)
{
vars:
"index" slist => getindices("$(tab)[$(sectionName)]");
# Be careful if the index string contains funny chars
"cindex[$(index)]" string => canonify("$(index)");
classes:
"edit_$(cindex[$(index)])" not => strcmp("$($(tab)[$(sectionName)][$(index)])","dontchange"),
comment => "Create conditions to make changes";
field_edits:
# If the line is there, but commented out, first uncomment it
# "#+\s*$(index)\s*=.*"
# select_region => INI_section(escape("$(sectionName)")),
# edit_field => col("\s*=\s*","1","$(index)","set"),
# if => "edit_$(cindex[$(index)])";
# match a line starting like the key something
"\s*$(index)\s*=.*"
edit_field => col("\s*=\s*","2","$($(tab)[$(sectionName)][$(index)])","set"),
select_region => INI_section(escape("$(sectionName)")),
classes => results("bundle", "set_variable_values_ini_not_$(cindex[$(index)])"),
if => "edit_$(cindex[$(index)])";
delete_lines:
"!include.*";
insert_lines:
"[$(sectionName)]"
location => start,
comment => "Insert lines";
"$(index)=$($(tab)[$(sectionName)][$(index)])"
select_region => INI_section(escape("$(sectionName)")),
if => "!(set_variable_values_ini_not_$(cindex[$(index)])_kept|set_variable_values_ini_not_$(cindex[$(index)])_repaired).edit_$(cindex[$(index)])";
}
bundle agent install_mysql_client
{
@ -178,19 +261,25 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
bundle agent create_mysql_db(cfg)
{
classes:
"type_$(mysql.type)" ;
vars:
"db_name" string => "$(cfg[db_name])";
"db_user" string => "$(cfg[db_user])";
"host" string => "$(cfg[db_user_host])";
"db_pass" string => "$(cfg[db_pass])";
type_mariadb::
"args" string => "-e \"CREATE DATABASE IF NOT EXISTS $(db_name); GRANT ALL PRIVILEGES ON $(db_name).* TO '$(db_user)'@'$(host)' IDENTIFIED BY '$(db_pass)'; \" ";
type_mysql8::
"args" string => "-e \"CREATE DATABASE IF NOT EXISTS $(db_name); CREATE USER IF NOT EXISTS '$(db_user)'@'$(host)'; ALTER USER '$(db_user)'@'$(host)' IDENTIFIED BY '$(db_pass)'; GRANT ALL PRIVILEGES ON $(db_name).* TO '$(db_user)'@'$(host)';\" ";
commands:
debian::
"$(mysql.mysql_cmd)"
args => "$(args)",
inform => "false";
"$(mysql.mysql_cmd)"
args => "$(args)",
inform => "false";
reports:
}