File: validate.pp

package info (click to toggle)
puppet-module-michaeltchapman-galera 0.7.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 316 kB
  • sloc: ruby: 453; sh: 79; makefile: 4
file content (79 lines) | stat: -rw-r--r-- 2,014 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# == Class galera::validate
#
# This class will ensure that the mysql cluster
# can accept connections at the point where the
# mysql::server resource is marked as complete.
#
# This is used because after returning success,
# the service is still not quite ready.
#
# === Parameters
#
# [*user*]
#   (optional) The mysql user to use.
#    Defaults to $galera::status_user
#
# [*password*]
#   (optional) The password for the mysql user.
#    Defaults to $galera::status_password
#
# [*host*]
#   (optional) The mysql host to check.
#    Defaults to $galera::status_host
#
# [*retries*]
#   (optional) Number of times to retry connection
#   Defaults to 20
#
# [*delay*]
#   (optional) Seconds to sleep between attempts.
#   Defaults to 3
#
# [*action*]
#   (optional) The mysql command to run
#   Defaults to 'select count(1);'
#
# [*catch*]
#   (optional) A string that if present indicates failure
#   Defaults to 'ERROR'
#
# [*inv_catch*]
#   (optional) A string that if not present indicates failure
#   Defaults to undef
#
class galera::validate(
  $user      = $galera::status_user,
  $password  = $galera::status_password,
  $host      = $galera::bind_address,
  $retries   = 20,
  $delay     = 3,
  $action    = 'select count(1);',
  $catch     = 'ERROR',
  $inv_catch = 'undef'
) {
  include galera::status

  if $catch {
    $truecatch = $catch
  } elsif $inv_catch {
    $truecatch = " -v ${inv_catch}"
  } else {
    fail('No catch method specified in galera validation script')
  }

  $cmd = "mysql --host=${host} --user=${user} --password=${password} -e '${action}'"
  exec { 'validate_connection':
    path        => '/usr/bin:/bin:/usr/sbin:/sbin',
    provider    => shell,
    command     => $cmd,
    tries       => $retries,
    try_sleep   => $delay,
    subscribe   => Service['mysqld'],
    refreshonly => true,
    before      => Anchor['mysql::server::end'],
    require     => Class['galera::status']
  }

  Exec<| title == 'bootstrap_galera_cluster' |> ~> Exec['validate_connection']
}