contain with predefined useshell added
This commit is contained in:
		
							parent
							
								
									2b14b23ff1
								
							
						
					
					
						commit
						453e7c2a0e
					
				
							
								
								
									
										61
									
								
								mysql.cf
								
								
								
								
							
							
						
						
									
										61
									
								
								mysql.cf
								
								
								
								
							| 
						 | 
				
			
			@ -16,24 +16,31 @@ vars:
 | 
			
		|||
		"cfg_file" string => "/usr/local/etc/mysql/my.cnf";
 | 
			
		||||
		"mysql_cmd" string => "/usr/local/bin/mysql";
 | 
			
		||||
	debian::
 | 
			
		||||
		"pkg"  string => "mariadb-server";
 | 
			
		||||
		"pkg"  slist => {"mariadb-common", "mariadb-client", "mariadb-server"};
 | 
			
		||||
		"service_name" string => "mysql";
 | 
			
		||||
		"cfg_file" string => "/etc/mysql/my.cnf";
 | 
			
		||||
		"mysql_cmd" string => "/usr/bin/mysql";
 | 
			
		||||
commands:
 | 
			
		||||
#	debian&mysql_repaired::
 | 
			
		||||
#	"/usr/bin/mysql_install_db"
 | 
			
		||||
#		depends_on => { "mysql_pkgs_installed" },
 | 
			
		||||
#		handle => "mysql_db_installed";
 | 
			
		||||
 | 
			
		||||
files:
 | 
			
		||||
 | 
			
		||||
	"$(cfg_file)" 
 | 
			
		||||
	create => "true",
 | 
			
		||||
	perms => m("644"),
 | 
			
		||||
	edit_template => "$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/my.cnf.mustache",
 | 
			
		||||
	template_method => "mustache",
 | 
			
		||||
	handle => "mysql_cfg_created",
 | 
			
		||||
	depends_on => {"mysql_pkgs_installed"},
 | 
			
		||||
#	depends_on => {"mysql_db_installed"},
 | 
			
		||||
	classes => if_repaired("mysql_repaired");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
methods:
 | 
			
		||||
	"any" usebundle => wmde_install_packages("$(mysql.pkg)","mysql");
 | 
			
		||||
	"any" usebundle => wmde_install_packages(@(mysql.pkg),"mysql"),
 | 
			
		||||
		depends_on => { "mysql_cfg_created" };
 | 
			
		||||
 | 
			
		||||
services:
 | 
			
		||||
	"$(service_name)"
 | 
			
		||||
| 
						 | 
				
			
			@ -49,6 +56,52 @@ services:
 | 
			
		|||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
body contain mysql_cmd
 | 
			
		||||
{
 | 
			
		||||
	useshell=>"useshell";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bundle agent mysql_table_exists(dbdef,table_name)
 | 
			
		||||
{
 | 
			
		||||
vars:
 | 
			
		||||
	"pass_arg" string => ifelse ( isvariable("dbdef[db_pass]"),
 | 
			
		||||
				"-p$(dbdef[db_pass])",""
 | 
			
		||||
			);
 | 
			
		||||
	"host_arg" string => ifelse ( isvariable("dbdef[db_host]"),
 | 
			
		||||
				"-h$(dbdef[db_host])",""
 | 
			
		||||
			);
 | 
			
		||||
	"user_arg" string => ifelse ( isvariable("dbdef[db_user]"),
 | 
			
		||||
				"-u$(dbdef[db_user])",""
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
	"xargs" string => "$(pass_arg) $(host_arg) $(user_arg)";
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	"classname" string => "mysql_$(dbdef[db_name])_$(table_name)_exists";
 | 
			
		||||
 | 
			
		||||
	"cmd" string => 'if mysql $(xargs) -e "show tables LIKE \'$(table_name)\'" $(dbdef[db_name]) | grep -q \'$(table_name)\'; then echo "+$(classname)"; else echo "-$(classname)"; fi';
 | 
			
		||||
	#"cmd" string => '"if mysql -e \\\"show tables"';
 | 
			
		||||
#	"cmdfile" string => hash("$cmd)","sha256");
 | 
			
		||||
 | 
			
		||||
#files:
 | 
			
		||||
#	"/tmp/$(cmdfile)"
 | 
			
		||||
#		create => "true",
 | 
			
		||||
#		content => "$(cmd)",
 | 
			
		||||
#		handle => "mysql_$(cmdfile)_created";
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
commands:
 | 
			
		||||
	"$(cmd)"
 | 
			
		||||
		contain => mysql_cmd,
 | 
			
		||||
		inform => "false",
 | 
			
		||||
		module => "true";
 | 
			
		||||
 | 
			
		||||
reports:
 | 
			
		||||
#	"CMD: $(cmd)";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bundle agent create_mysql_db(cfg)
 | 
			
		||||
{
 | 
			
		||||
vars:
 | 
			
		||||
| 
						 | 
				
			
			@ -65,5 +118,7 @@ commands:
 | 
			
		|||
		args => "$(args)",
 | 
			
		||||
		inform => "false";
 | 
			
		||||
 | 
			
		||||
#mysql -u <username> -p -e "USE <database_name>;" && mysql -u <username> -p -e "SHOW TABLES LIKE '<table_name>';" | grep -q '<table_name>' && exit 0 || exit 1
 | 
			
		||||
 | 
			
		||||
reports:
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue