diff --git a/.kitchen.yml b/.kitchen.yml index 398c773..ae8d95c 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -25,7 +25,9 @@ suites: run_list: - role[bareos_server] attributes: - +# bareos: +# dbpassword: 'ChangeMe1234#' +# dbaddress: '127.0.0.1' - name: server-host-pools run_list: - role[bareos_server] diff --git a/recipes/client.rb b/recipes/client.rb index 718a2c3..fac9eec 100644 --- a/recipes/client.rb +++ b/recipes/client.rb @@ -41,7 +41,13 @@ variables( bareos_server: bareos_server ) - notifies :reload, 'service[bareos-fd]', :immediately + notifies :run, 'execute[restart-fd]', :immediately +end + +execute 'restart-fd' do + command 'bareos-fd -t -c /etc/bareos/bareos-fd.conf' + action :nothing + notifies :restart, 'service[bareos-fd]', :delayed end service 'bareos-fd' do diff --git a/recipes/database.rb b/recipes/database.rb index 868863a..fcdeca9 100644 --- a/recipes/database.rb +++ b/recipes/database.rb @@ -54,6 +54,7 @@ end if database == 'postgresql' + execute 'create_database' do command 'su postgres -c "/usr/lib/bareos/scripts/create_bareos_database" && touch /usr/lib/bareos/.dbcreated' creates '/usr/lib/bareos/.dbcreated' @@ -61,13 +62,13 @@ end execute 'create_tables' do - command 'su postgres -c "/usr/lib/bareos/scripts/make_bareos_tables" && touch /usr/lib/bareos/.dbtablescreated' + command 'su postgres -s /bin/bash -c "/usr/lib/bareos/scripts/make_bareos_tables" && touch /usr/lib/bareos/.dbtablescreated' creates '/usr/lib/bareos/.dbtablescreated' action :run end execute 'grant_privileges' do - command 'su postgres -c "/usr/lib/bareos/scripts/grant_bareos_privileges" && touch /usr/lib/bareos/.dbprivgranted' + command 'su postgres -s /bin/bash -c "/usr/lib/bareos/scripts/grant_bareos_privileges" && touch /usr/lib/bareos/.dbprivgranted' creates '/usr/lib/bareos/.dbprivgranted' action :run end diff --git a/recipes/server.rb b/recipes/server.rb index 89e7295..babd212 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -46,9 +46,10 @@ db_driver: node['bareos']['dbdriver'], db_name: node['bareos']['dbname'], db_user: node['bareos']['dbuser'], - db_password: node['bareos']['dbpassword'] + db_password: node['bareos']['dbpassword'], + db_address: node['bareos']['dbaddress'] ) - notifies :reload, 'service[bareos-dir]', :immediately + notifies :run, 'execute[reload-dir]', :delayed end # Handle seperate host config files @@ -66,17 +67,23 @@ bareos_clients.each do template "/etc/bareos/bareos-dir.d/hosts/#{node['hostname']}.conf" do source 'host.conf.erb' - owner 'root' - group 'root' - mode '0644' + owner 'bareos' + group 'bareos' + mode '0640' variables( bareos_clients: bareos_clients ) - notifies :reload, 'service[bareos-dir]', :immediately + notifies :run, 'execute[reload-dir]', :delayed end end end +execute 'reload-dir' do + command 'su - bareos -s /bin/sh -c "/usr/sbin/bareos-dir -t -c /etc/bareos/bareos-dir.conf"' + action :nothing + notifies :reload, 'service[bareos-dir]', :delayed +end + service 'bareos-dir' do supports status: true, restart: true, reload: false action [:enable, :start] diff --git a/recipes/storage.rb b/recipes/storage.rb index 10bf830..6af3d37 100644 --- a/recipes/storage.rb +++ b/recipes/storage.rb @@ -46,7 +46,13 @@ variables( bareos_server: bareos_server ) - notifies :reload, 'service[bareos-dir]', :immediately + notifies :run, 'execute[restart-sd]', :immediately +end + +execute 'restart-sd' do + command 'bareos-sd -t -c /etc/bareos/bareos-sd.conf' + action :nothing + notifies :restart, 'service[bareos-sd]', :delayed end service 'bareos-sd' do diff --git a/templates/default/bareos-dir.conf.erb b/templates/default/bareos-dir.conf.erb index 91a73c9..5eacb8c 100644 --- a/templates/default/bareos-dir.conf.erb +++ b/templates/default/bareos-dir.conf.erb @@ -102,6 +102,9 @@ Catalog { dbname = "<%= @db_name %>" dbuser = "<%= @db_user %>" dbpassword = "<%= @db_password %>" +<% if @db_address != nil %> + dbaddress = "<%= @db_address %>" +<% end %> } Console { diff --git a/test/integration/roles/bareos_server.json b/test/integration/roles/bareos_server.json index bd57ad0..f078924 100644 --- a/test/integration/roles/bareos_server.json +++ b/test/integration/roles/bareos_server.json @@ -9,8 +9,8 @@ "chef_type": "role", "run_list": [ "role[bareos_base]", - "recipe[chef-bareos::database]", "recipe[chef-bareos::server]", + "recipe[chef-bareos::database]", "recipe[chef-bareos::storage]", "recipe[chef-bareos::workstation]" ],