Guest User

Untitled

a guest
Feb 27th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. define bareos::director::catalog (
  2. $ensure = present,
  3. $db_address = undef,
  4. $db_driver = undef,
  5. $db_name = undef,
  6. $db_password = undef,
  7. $db_port = undef,
  8. $db_socket = undef,
  9. $db_user = undef,
  10. $description = undef,
  11. $disable_batch_insert = undef,
  12. $exit_on_fatal = undef,
  13. $idle_timeout = undef,
  14. $inc_connections = undef,
  15. $max_connections = undef,
  16. $min_connections = undef,
  17. $multiple_connections = undef,
  18. $reconnect = undef,
  19. $validate_timeout = undef,
  20. ) {
  21. include ::bareos::director
  22.  
  23. $_resource = 'Catalog'
  24. $_resource_dir = 'catalog'
  25.  
  26. unless $ensure in [ 'present', 'absent' ] {
  27. fail('Invalid value for ensure')
  28. }
  29.  
  30. if $ensure == 'present' {
  31.  
  32. $_env = [
  33. "db_name=${db_name}",
  34. "PGDATABASE=${db_name}",
  35. "db_user=${db_user}",
  36. "PGUSER=${db_user}",
  37. "db_password=${db_password}",
  38. "PGPASSWORD=${db_password}",
  39. "db_address=${db_address}",
  40. "PGHOST=${db_address}",
  41. "PGPORT=${db_port}",
  42. ]
  43.  
  44. case $db_driver {
  45. 'sqlite3': {
  46. # code
  47. $_commands = '/usr/lib/bareos/scripts/create_bareos_database && /usr/lib/bareos/scripts/make_bareos_tables'
  48. }
  49. 'mysql': {
  50. # code
  51. $_mysql_port = $db_port ? {
  52. undef => '-P 3306',
  53. default => "-P ${db_port}",
  54. }
  55. $_mysql_args = "${_mysql_port} -h \$db_address -u \"\$db_user\" -p\"\$db_password\" -D \"\$db_name\""
  56. $_command = "/usr/lib/bareos/scripts/create_bareos_database ${_mysql_args} && /usr/lib/bareos/scripts/make_bareos_tables ${_mysql_args}"
  57. }
  58. 'postgresql': {
  59. $_command = '/usr/lib/bareos/scripts/create_bareos_database && /usr/lib/bareos/scripts/make_bareos_tables'
  60. }
  61. default: {
  62. fail("DB driver '${db_driver}' is not support")
  63. }
  64. }
  65.  
  66. File <| |> -> exec { "bareos director init catalog ${name}":
  67. command => $_command,
  68. environment => $_env,
  69. subscribe => File["${::bareos::director::config_dir}/${_resource_dir}/${name}.conf"],
  70. notify => Service[$::bareos::director::service_name],
  71. refreshonly => true,
  72. }
  73.  
  74. $_settings = bareos_settings(
  75. [$name, 'Name', 'name', true],
  76. [$description, 'Description', 'string', false],
  77. [$db_address, 'Db Address', 'string', false],
  78. [$db_driver, 'Db Driver', 'string', true],
  79. [$db_name, 'Db Name', 'string', true],
  80. [$db_password, 'Db Password', 'autopassword', false],
  81. [$db_port, 'Db Port', 'pint32', false],
  82. [$db_socket, 'Db Socket', 'string', false],
  83. [$db_user, 'Db User', 'string', false],
  84. [$disable_batch_insert, 'Disable Batch Insert', 'boolean', false],
  85. [$exit_on_fatal, 'Exit On Fatal', 'boolean', false],
  86. [$idle_timeout, 'Idle Timeout', 'pint32', false],
  87. [$inc_connections, 'Inc Connections', 'pint32', false],
  88. [$max_connections, 'Max Connections', 'pint32', false],
  89. [$min_connections, 'Min Connections', 'pint32', false],
  90. [$multiple_connections, 'Multiple Connections', 'bit', false],
  91. [$reconnect, 'Reconnect', 'boolean', false],
  92. [$validate_timeout, 'Validate Timeout', 'pint32', false]
  93. )
  94. }
  95.  
  96. file { "${::bareos::director::config_dir}/${_resource_dir}/${name}.conf":
  97. ensure => $ensure,
  98. mode => $::bareos::file_mode,
  99. owner => $::bareos::file_owner,
  100. group => $::bareos::file_group,
  101. content => template('bareos/resource.erb'),
  102. notify => [
  103. Service[$::bareos::director::service_name],
  104. ]
  105. }
  106.  
  107. }
Add Comment
Please, Sign In to add comment