Compare commits

...

5 Commits

Author SHA1 Message Date
Tube ab21a02be7 CentOs uses per default 8.0 2023-11-13 01:18:49 +01:00
Tube 1b3ac8039e New bundle mysql_resore_conditional 2023-11-13 01:18:10 +01:00
Tube ee82bafb47 enables service under FreeBSD 2023-11-13 01:17:32 +01:00
Tube 2d932565b6 Added bundle wmde_enable_service (only needed for FreeBSD currently) 2023-11-13 01:15:30 +01:00
Tube 5f9b1b1edc added a matomo tracker function 2023-11-12 01:38:11 +01:00
4 changed files with 154 additions and 7 deletions

View File

@ -56,6 +56,7 @@ vars:
"log_dir_group" string => "wheel";
"service_name" string => "apache24";
"service_cfg_name" string => "apache24";
"www_user" string => "www";
"www_group" string => "www";
"mime_types" string => "/usr/local/etc/apache24/mime.types";
@ -78,6 +79,7 @@ vars:
{m:"proxy",f:"mod_proxy"},
{m:"proxy_http",f:"mod_proxy_http"},
{m:"proxy_http2",f:"mod_proxy_http2"},
{m:"remoteip",f:"mod_remoteip"}
]';
@ -276,7 +278,7 @@ files:
methods:
"any" usebundle => wmde_enable_service("apache");
"any" usebundle => wmde_service("$(apache.service_name)","apache_kept","apache_repaired|php_repaired"),
depends_on => @(apache.service_deps) ;
@ -436,3 +438,95 @@ methods:
reports:
}
bundle agent apache_matomo
(site)
{
vars:
"pid" string => "/var/run/matomo-logger-$(site[domain]).pid";
"log" string => "$(apache.log_dir)/$(site[domain])-access.log";
"siteid" string => "$(site[matomoid])";
freebsd::
"analyt_cmd" string => "/usr/local/bin/python3.9 /var/www/matomo/misc/log-analytics/import_logs.py";
debian::
"analyt_cmd" string => "/usr/bin/python3 /var/www/matomo/misc/log-analytics/import_logs.py";
centos::
"analyt_cmd" string => "/usr/bin/python3 /var/www/matomo/misc/log-analytics/import_logs.py";
matomo::
"cmd" string => "/usr/bin/pkill -P `cat $(pid)` ; exec /bin/sh -c 'echo $$ > $(pid); /usr/bin/tail -n+1 -f $(log) | $(analyt_cmd) --token-auth=$(site[matomotoken]) --disable-bulk-tracking --idsite=$(siteid) --url=$(site[matomosite]) --exclude-path=/wp-login.php --exclude-path=/wp-json/* --recorders=1 --recorder-max-payload-size=1 --log-format-name=ncsa_extended --exclude-path=*.php --exclude-path=/wp-admin/* - > /dev/null' ";
!matomo::
"cmd" string => "";
any::
"cmd_esc" string => escape ($(cmd));
# "cmd": "$(cmd_esc)",
"site_str" string => storejson(@(site));
# "site_json" string => '{
# "site" : "$(site_str)"
# }';
"site_json" string => '{
"cmd": "$(cmd)",
"service": "$(apache.service_name)",
"site": $(site_str)
}';
"template_file"
string => "$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/weblogrot.mustache";
methods:
"any" usebundle => install_logrot;
files:
"$(logrot.dir)/$(site[domain])"
create => "true",
edit_defaults => backup("false"),
edit_template => "$(template_file)",
template_method => "mustache";
# template_data => parsejson("$(site_json)");
matomo::
"$(pid)"
create => "true";
classes:
"matomo" expression => isvariable("site[matomoid]");
commands:
matomo::
"/bin/sh -c "
args => "'kill -0 `cat $(pid)` && echo -start_matomo || echo +start_matomo'",
inform => "false",
module => "true";
methods:
start_matomo::
"call" usebundle => daemonize( "$(cmd)" );
reports:
#start_matomo::
# "MUST START - WHY";
#"ESC ESC $(site_json)";
matomo::
}
body edit_defaults backup( edit_backup )
{
edit_backup => "$(edit_backup)";
}

15
lib.cf
View File

@ -103,7 +103,22 @@ body service_method wmde
}
bundle agent wmde_enable_service(bundlename)
{
vars:
freebsd::
# "cha" string => "$(bundlename).service_cfg_name";
"filename" string => "/etc/rc.conf.d/$($(bundlename).service_cfg_name)";
files:
freebsd::
"$(filename)"
create => "true",
perms => m("644"),
content => "$($(bundlename).service_cfg_name)_enable=YES";
reports:
# "FREEBSD: $(filename) $(cha)";
}
bundle agent wmde_service(service_name,start_cond, restart_cond)
{

View File

@ -9,7 +9,8 @@ vars:
"default_cfg" data => '{
"bind_address":"127.0.0.1",
"user":"mysql",
"port":"3306"
"port":"3306",
"backup_dir":"/var/backups"
}';
"cfg" data => mergedata(@(default_cfg),@(cfg_param));
@ -71,10 +72,11 @@ files:
"$(cfg_file)"
create => "true",
#create => "true",
perms => m("644"),
edit_template => "$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/my.cnf.mustache",
template_method => "mustache",
copy_from => seed_cp("$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/my.cnf.mustache"),
# edit_template => "$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/my.cnf.mustache",
# template_method => "mustache",
handle => "mysql_cfg_created",
depends_on => {"mysql_cfg_dir_created"},
classes => if_repaired("mysql_repaired");
@ -123,6 +125,7 @@ vars:
"j" string => storejson(@(cfg));
methods:
"any" usebundle => mysql(@(cfg));
"any" usebundle => wmde_install_packages(@(mysql.server_pkgs),"mysql_server");
files:
@ -315,25 +318,38 @@ bundle agent create_mysql_db(cfg)
{
classes:
"type_$(mysql.type)" ;
# "do_restore" expression => isvariable("cfg[restore]");
"do_restore" expression => strcmp("$(cfg[restore])","true");
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 RELOAD ON *.* to '$(db_user)'@'$(host)'; GRANT ALL PRIVILEGES ON $(db_name).* TO '$(db_user)'@'$(host)';\" ";
methods:
do_restore::
"any" usebundle => restore_mysql_db_conditional(@(cfg),"$(mysql.cfg[backup_dir])/$(cfg[db_name])-dmp.sql"),
depends_on => {"mysql_$(cfg[db_name])_created"};
commands:
"$(mysql.mysql_cmd)"
args => "$(args)",
handle => "mysql_$(cfg[db_name])_created",
inform => "false";
reports:
do_restore::
"DO RESTORE";
!do_restore::
"DO_NOT_RESTORE";
}
@ -346,3 +362,25 @@ commands:
contain => wmde_cmd_useshell;
}
bundle agent restore_mysql_db_conditional(cfg,file)
{
classes:
"backup_exists" expression => fileexists("$(file)");
vars:
"table_exists" string => "mysql_$(cfg[db_name])_$(cfg[check_table])_exists";
methods:
"any" usebundle => mysql_table_exists(@(cfg),"$(cfg[check_table])");
"!$(table_exists)&backup_exists"::
"any" usebundle => restore_mysql_db(@(cfg),"$(file)");
reports:
"conditional $(cfg[check_table])_exists";
"FILE: $(file)";
"$(table_exists)"::
"$(table_exists) exists";
"!$(table_exists)&backup_exists"::
"$(table_exists) does not existsi, can restore";
}

2
php.cf
View File

@ -226,7 +226,7 @@ vars:
centos::
"cli_exe" string => "/usr/bin/php";
"version" string => "8.2";
"version" string => "8.0";
"fpm_pkgs" slist => { "php-fpm" };
"fpm_service_name" string => "php$(version)-fpm";
"fpm_socket" string => "/run/php-fpm/www.sock";