From bf57203091abd4092a30a179ed246dff3fe185fb Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Sun, 12 Jul 2015 10:54:26 +0200 Subject: [PATCH 01/16] add dbpassword attribute for dbconnection to test also network connections to database --- .kitchen.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.kitchen.yml b/.kitchen.yml index 398c773..f4ae3e0 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -25,6 +25,8 @@ suites: run_list: - role[bareos_server] attributes: + bareos: + dbpassword: 'ChangeMe1234#' - name: server-host-pools run_list: From ddaaa4653cbd5bf8e1100fa5453ff2317b3b779d Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Sun, 12 Jul 2015 10:55:15 +0200 Subject: [PATCH 02/16] add default network address for db connections --- attributes/default.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/attributes/default.rb b/attributes/default.rb index 134aef4..69f56ee 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -29,6 +29,7 @@ default['bareos']['dbname'] = 'bareos' default['bareos']['dbuser'] = 'bareos' default['bareos']['dbpassword'] = '' +default['bareos']['dbaddress'] = '127.0.0.1' # Clients list default['bareos']['clients'] = [] From 2aeaf39d74b96ea680a594ee2c01f8be04efebb7 Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Sun, 12 Jul 2015 10:56:01 +0200 Subject: [PATCH 03/16] add line for db address configuration --- templates/default/bareos-dir.conf.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/default/bareos-dir.conf.erb b/templates/default/bareos-dir.conf.erb index 91a73c9..5e30a88 100644 --- a/templates/default/bareos-dir.conf.erb +++ b/templates/default/bareos-dir.conf.erb @@ -102,6 +102,7 @@ Catalog { dbname = "<%= @db_name %>" dbuser = "<%= @db_user %>" dbpassword = "<%= @db_password %>" + dbaddress = "<%= @db_address %>" } Console { From 6fcee622c4b3e95f6de2a03917160e16f5b0e73e Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Sun, 12 Jul 2015 10:57:41 +0200 Subject: [PATCH 04/16] add configuration test before do reload or restarting daemons --- recipes/client.rb | 8 +++++++- recipes/server.rb | 19 +++++++++++++------ recipes/storage.rb | 8 +++++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/recipes/client.rb b/recipes/client.rb index 718a2c3..ec385d4 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[reload-fd]', :immediately +end + +execute "reload-fd" do + command "bareos-fd -t -c /etc/bareos/bareos-fd.conf" + action :nothing + notifies :reload, 'service[bareos-fd]', :delayed end service 'bareos-fd' do diff --git a/recipes/server.rb b/recipes/server.rb index 89e7295..22037cf 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 "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..09d006a 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[reload-dir]', :immediately +end + +execute "reload-sd" do + command "bareos-sd -t -c /etc/bareos/bareos-sd.conf" + action :nothing + notifies :reload, 'service[bareos-sd]', :delayed end service 'bareos-sd' do From 89516287c010d9aa00a9474331eb45225481c9e9 Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Sun, 12 Jul 2015 11:00:36 +0200 Subject: [PATCH 05/16] use database cookbook where it was possible, changed user to create the tables to bareos, because if I use the bareos-dir check there was a problem with the table permissions on postgresql. There fore the sh shell was needed for the bareos user. --- recipes/database.rb | 61 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/recipes/database.rb b/recipes/database.rb index 868863a..aa412c5 100644 --- a/recipes/database.rb +++ b/recipes/database.rb @@ -17,6 +17,7 @@ # limitations under the License. # + package 'bareos-database-tools' do action :install end @@ -54,21 +55,61 @@ 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' - action :run + + user 'bareos' do + shell '/bin/sh' + action :modify + end + + include_recipe "database::postgresql" + + postgresql_connection_info = { + :host => "127.0.0.1", + :port => node['postgresql']['config']['port'], + :username => 'postgres', + :password => node['postgresql']['password']['postgres'] + } + + + postgresql_database_user 'bareos' do + connection postgresql_connection_info + password node['bareos']['dbpassword'] + action :create end + postgresql_database 'bareos' do + connection postgresql_connection_info + template 'template0' + encoding 'SQL_ASCII' + collation 'C' + tablespace 'DEFAULT' + connection_limit '-1' + owner 'bareos' + action :create + end + + postgresql_database_user 'bareos' do + connection postgresql_connection_info + database_name 'bareos' + privileges [:all] + action :grant + end + +# 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' +# action :run +# end + execute 'create_tables' do - command 'su postgres -c "/usr/lib/bareos/scripts/make_bareos_tables" && touch /usr/lib/bareos/.dbtablescreated' + command 'su bareos -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' - creates '/usr/lib/bareos/.dbprivgranted' - action :run - end +# execute 'grant_privileges' do +# command 'su postgres -c "/usr/lib/bareos/scripts/grant_bareos_privileges" && touch /usr/lib/bareos/.dbprivgranted' +# creates '/usr/lib/bareos/.dbprivgranted' +# action :run +# end end From fb6df964fca1770b256f7c59f0ba95200f4560db Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Sun, 12 Jul 2015 11:01:56 +0200 Subject: [PATCH 06/16] add database cookbook to create users and databases for bareos --- metadata.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/metadata.rb b/metadata.rb index 0c3eac4..b8e14a0 100644 --- a/metadata.rb +++ b/metadata.rb @@ -11,6 +11,7 @@ supports 'ubuntu', '>= 12.04' depends 'apt' +depends 'database' depends 'openssl' depends 'postgresql' depends 'yum' From 1cd84c638be8d531fcbaebdf5234f842fdc261e3 Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Sun, 12 Jul 2015 12:50:41 +0200 Subject: [PATCH 07/16] changed some syntax issues --- recipes/client.rb | 4 ++-- recipes/database.rb | 17 ++--------------- recipes/server.rb | 4 ++-- recipes/storage.rb | 4 ++-- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/recipes/client.rb b/recipes/client.rb index ec385d4..31ce8e8 100644 --- a/recipes/client.rb +++ b/recipes/client.rb @@ -44,8 +44,8 @@ notifies :run, 'execute[reload-fd]', :immediately end -execute "reload-fd" do - command "bareos-fd -t -c /etc/bareos/bareos-fd.conf" +execute 'reload-fd' do + command 'bareos-fd -t -c /etc/bareos/bareos-fd.conf' action :nothing notifies :reload, 'service[bareos-fd]', :delayed end diff --git a/recipes/database.rb b/recipes/database.rb index aa412c5..5d1fac2 100644 --- a/recipes/database.rb +++ b/recipes/database.rb @@ -61,16 +61,15 @@ action :modify end - include_recipe "database::postgresql" + include_recipe 'database::postgresql' postgresql_connection_info = { - :host => "127.0.0.1", + :host => '127.0.0.1', :port => node['postgresql']['config']['port'], :username => 'postgres', :password => node['postgresql']['password']['postgres'] } - postgresql_database_user 'bareos' do connection postgresql_connection_info password node['bareos']['dbpassword'] @@ -95,21 +94,9 @@ action :grant end -# 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' -# action :run -# end - execute 'create_tables' do command 'su bareos -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' -# creates '/usr/lib/bareos/.dbprivgranted' -# action :run -# end end diff --git a/recipes/server.rb b/recipes/server.rb index 22037cf..9ae9371 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -78,8 +78,8 @@ end end -execute "reload-dir" do - command "bareos-dir -t -c /etc/bareos/bareos-dir.conf" +execute 'reload-dir' do + command 'bareos-dir -t -c /etc/bareos/bareos-dir.conf' action :nothing notifies :reload, 'service[bareos-dir]', :delayed end diff --git a/recipes/storage.rb b/recipes/storage.rb index 09d006a..171741b 100644 --- a/recipes/storage.rb +++ b/recipes/storage.rb @@ -49,8 +49,8 @@ notifies :run, 'execute[reload-dir]', :immediately end -execute "reload-sd" do - command "bareos-sd -t -c /etc/bareos/bareos-sd.conf" +execute 'reload-sd' do + command 'bareos-sd -t -c /etc/bareos/bareos-sd.conf' action :nothing notifies :reload, 'service[bareos-sd]', :delayed end From 81905ba2e8da5fad5a7a8d3177591351d1e03011 Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Sun, 12 Jul 2015 12:59:06 +0200 Subject: [PATCH 08/16] fixed some rubocop issues --- recipes/database.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/recipes/database.rb b/recipes/database.rb index 5d1fac2..89e4b4f 100644 --- a/recipes/database.rb +++ b/recipes/database.rb @@ -17,7 +17,6 @@ # limitations under the License. # - package 'bareos-database-tools' do action :install end @@ -90,7 +89,7 @@ postgresql_database_user 'bareos' do connection postgresql_connection_info database_name 'bareos' - privileges [:all] + privileges [:all] action :grant end From a253f4cb73e52d473a43cd7882d6973c8ac1e1f9 Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Mon, 13 Jul 2015 09:16:54 +0200 Subject: [PATCH 09/16] changed reload action to restart --- recipes/client.rb | 6 +++--- recipes/storage.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/recipes/client.rb b/recipes/client.rb index 31ce8e8..fac9eec 100644 --- a/recipes/client.rb +++ b/recipes/client.rb @@ -41,13 +41,13 @@ variables( bareos_server: bareos_server ) - notifies :run, 'execute[reload-fd]', :immediately + notifies :run, 'execute[restart-fd]', :immediately end -execute 'reload-fd' do +execute 'restart-fd' do command 'bareos-fd -t -c /etc/bareos/bareos-fd.conf' action :nothing - notifies :reload, 'service[bareos-fd]', :delayed + notifies :restart, 'service[bareos-fd]', :delayed end service 'bareos-fd' do diff --git a/recipes/storage.rb b/recipes/storage.rb index 171741b..6af3d37 100644 --- a/recipes/storage.rb +++ b/recipes/storage.rb @@ -46,13 +46,13 @@ variables( bareos_server: bareos_server ) - notifies :run, 'execute[reload-dir]', :immediately + notifies :run, 'execute[restart-sd]', :immediately end -execute 'reload-sd' do +execute 'restart-sd' do command 'bareos-sd -t -c /etc/bareos/bareos-sd.conf' action :nothing - notifies :reload, 'service[bareos-sd]', :delayed + notifies :restart, 'service[bareos-sd]', :delayed end service 'bareos-sd' do From 2183d9638b7220c8afbd99ce872584977a735595 Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Tue, 14 Jul 2015 14:58:40 +0200 Subject: [PATCH 10/16] remove the shell from bareos user, and use shell only temporary for db table creation --- recipes/database.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/recipes/database.rb b/recipes/database.rb index 89e4b4f..a2e6625 100644 --- a/recipes/database.rb +++ b/recipes/database.rb @@ -55,11 +55,6 @@ if database == 'postgresql' - user 'bareos' do - shell '/bin/sh' - action :modify - end - include_recipe 'database::postgresql' postgresql_connection_info = { @@ -94,7 +89,7 @@ end execute 'create_tables' do - command 'su bareos -c "/usr/lib/bareos/scripts/make_bareos_tables" && touch /usr/lib/bareos/.dbtablescreated' + command 'su - bareos -s /bin/sh -c "/usr/lib/bareos/scripts/make_bareos_tables" && touch /usr/lib/bareos/.dbtablescreated' creates '/usr/lib/bareos/.dbtablescreated' action :run end From 2ed69587286e638ff5d1f99875502ec332f33a70 Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Tue, 14 Jul 2015 17:56:36 +0200 Subject: [PATCH 11/16] use local postgresql socket connection per default, and do bareos-dir tests as bareos user --- .kitchen.yml | 6 +++--- attributes/default.rb | 1 - recipes/server.rb | 2 +- templates/default/bareos-dir.conf.erb | 2 ++ 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index f4ae3e0..ae8d95c 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -25,9 +25,9 @@ suites: run_list: - role[bareos_server] attributes: - bareos: - dbpassword: 'ChangeMe1234#' - +# bareos: +# dbpassword: 'ChangeMe1234#' +# dbaddress: '127.0.0.1' - name: server-host-pools run_list: - role[bareos_server] diff --git a/attributes/default.rb b/attributes/default.rb index 69f56ee..134aef4 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -29,7 +29,6 @@ default['bareos']['dbname'] = 'bareos' default['bareos']['dbuser'] = 'bareos' default['bareos']['dbpassword'] = '' -default['bareos']['dbaddress'] = '127.0.0.1' # Clients list default['bareos']['clients'] = [] diff --git a/recipes/server.rb b/recipes/server.rb index 9ae9371..3d2f61d 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -79,7 +79,7 @@ end execute 'reload-dir' do - command 'bareos-dir -t -c /etc/bareos/bareos-dir.conf' + command 'su - bareos -s /bin/sh -c "bareos-dir -t -c /etc/bareos/bareos-dir.conf"' action :nothing notifies :reload, 'service[bareos-dir]', :delayed end diff --git a/templates/default/bareos-dir.conf.erb b/templates/default/bareos-dir.conf.erb index 5e30a88..5eacb8c 100644 --- a/templates/default/bareos-dir.conf.erb +++ b/templates/default/bareos-dir.conf.erb @@ -102,7 +102,9 @@ Catalog { dbname = "<%= @db_name %>" dbuser = "<%= @db_user %>" dbpassword = "<%= @db_password %>" +<% if @db_address != nil %> dbaddress = "<%= @db_address %>" +<% end %> } Console { From 5996a13ae980744a86ec73460a225b968bef242b Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Tue, 14 Jul 2015 18:52:40 +0200 Subject: [PATCH 12/16] roled back to original version with using scripts only instead of using database cookbook --- recipes/database.rb | 43 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/recipes/database.rb b/recipes/database.rb index a2e6625..fcdeca9 100644 --- a/recipes/database.rb +++ b/recipes/database.rb @@ -55,42 +55,21 @@ if database == 'postgresql' - include_recipe 'database::postgresql' - - postgresql_connection_info = { - :host => '127.0.0.1', - :port => node['postgresql']['config']['port'], - :username => 'postgres', - :password => node['postgresql']['password']['postgres'] - } - - postgresql_database_user 'bareos' do - connection postgresql_connection_info - password node['bareos']['dbpassword'] - action :create - end - - postgresql_database 'bareos' do - connection postgresql_connection_info - template 'template0' - encoding 'SQL_ASCII' - collation 'C' - tablespace 'DEFAULT' - connection_limit '-1' - owner 'bareos' - action :create - end - - postgresql_database_user 'bareos' do - connection postgresql_connection_info - database_name 'bareos' - privileges [:all] - action :grant + 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' + action :run end execute 'create_tables' do - command 'su - bareos -s /bin/sh -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 -s /bin/bash -c "/usr/lib/bareos/scripts/grant_bareos_privileges" && touch /usr/lib/bareos/.dbprivgranted' + creates '/usr/lib/bareos/.dbprivgranted' + action :run + end end From ab60fbb45a2270576c06e43e017002d9efb2130b Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Tue, 14 Jul 2015 18:53:29 +0200 Subject: [PATCH 13/16] if using the install script, first run the server recipe because the database scripts needs to read the bareos-dir configuration --- test/integration/roles/bareos_server.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]" ], From a9ba9968c10f80282781f11011537915a975d005 Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Tue, 14 Jul 2015 19:22:53 +0200 Subject: [PATCH 14/16] removed the - in the bareos-dir check cause of issues with it in ubuntu. Debian I had to converge twice, otherwise it can't execute the bareos-dir check, don't know why, perhaps anyone has an idea. --- recipes/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/server.rb b/recipes/server.rb index 3d2f61d..adaf918 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -79,7 +79,7 @@ end execute 'reload-dir' do - command 'su - bareos -s /bin/sh -c "bareos-dir -t -c /etc/bareos/bareos-dir.conf"' + command 'su bareos -s /bin/sh -c "bareos-dir -t -c /etc/bareos/bareos-dir.conf"' action :nothing notifies :reload, 'service[bareos-dir]', :delayed end From b57a0014c3ed545c9d2875e72107675de1c25046 Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Wed, 15 Jul 2015 00:01:54 +0200 Subject: [PATCH 15/16] removed dependency --- metadata.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index b8e14a0..0c3eac4 100644 --- a/metadata.rb +++ b/metadata.rb @@ -11,7 +11,6 @@ supports 'ubuntu', '>= 12.04' depends 'apt' -depends 'database' depends 'openssl' depends 'postgresql' depends 'yum' From a1f85bbc54447f287879963d95b24f4ab69d92e0 Mon Sep 17 00:00:00 2001 From: Gerhard Sulzberger Date: Wed, 15 Jul 2015 10:18:25 +0200 Subject: [PATCH 16/16] use full path has solved the issues, now initial converge works with server-ubuntu-14, server-debian-78, server-centos66 --- recipes/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/server.rb b/recipes/server.rb index adaf918..babd212 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -79,7 +79,7 @@ end execute 'reload-dir' do - command 'su bareos -s /bin/sh -c "bareos-dir -t -c /etc/bareos/bareos-dir.conf"' + 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