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