Skip to content

Instantly share code, notes, and snippets.

@michaeltchapman
Created March 20, 2014 00:36
Show Gist options
  • Save michaeltchapman/9654908 to your computer and use it in GitHub Desktop.
Save michaeltchapman/9654908 to your computer and use it in GitHub Desktop.
define galera::validate(
$user,
$password,
$host,
$retries = 10,
$delay = 10,
$action = 'select user,host from mysql.user;'
$catch = 'ERROR'
)
{
$cmd = "mysql --host=${host} --user=${user} --password=${password} -e '${action}'"
exec { 'validate_connection':
path => '/usr/bin',
command => "ret=0; count=0; while [ \$count -lt ${retries} ]; do if ${cmd} | grep -q ${catch}; then ret=1; break; fi; sleep 1; count=\$((\$count + 1)); done; echo $ret | grep 0 -q;",
subscribe => Service['mysql'],
refreshonly => true,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment