From dc404c6f1e199f83036550c72ff09bcca8776c30 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 12 May 2016 21:33:45 +0100 Subject: [PATCH] Centralise definition of read/write and readonly database servers --- .../planet/files/default/replication-bin/users-agreed | 4 ++-- cookbooks/planet/templates/default/changesets.conf.erb | 2 +- cookbooks/planet/templates/default/replication.auth.erb | 2 +- cookbooks/planet/templates/default/users-agreed.conf.erb | 2 +- roles/planet.rb | 1 + roles/web-db.rb | 9 +++++++++ roles/web.rb | 8 +++++--- 7 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 roles/web-db.rb diff --git a/cookbooks/planet/files/default/replication-bin/users-agreed b/cookbooks/planet/files/default/replication-bin/users-agreed index 427910c05..707a65bfd 100644 --- a/cookbooks/planet/files/default/replication-bin/users-agreed +++ b/cookbooks/planet/files/default/replication-bin/users-agreed @@ -8,9 +8,9 @@ export PGPASSFILE=/etc/replication/users-agreed.conf echo "# user IDs < 286582 who have agreed to the contributor terms. " > $T/users_agreed echo "# any active user IDs >= 286582 would have agreed as part of the sign-up process." >> $T/users_agreed -psql -h ramoth.ic.openstreetmap.org -U planetdiff -t -c "select id from users where id < 286582 and terms_agreed is not null order by id asc" openstreetmap >> $T/users_agreed +psql -h <%= node[:web][:readonly_database_host] %> -U planetdiff -t -c "select id from users where id < 286582 and terms_agreed is not null order by id asc" openstreetmap >> $T/users_agreed -psql -h ramoth.ic.openstreetmap.org -U planetdiff -t -c "select id from users where terms_seen and terms_agreed is null order by id asc" openstreetmap > $T/users_disagreed +psql -h <%= node[:web][:readonly_database_host] %> -U planetdiff -t -c "select id from users where terms_seen and terms_agreed is null order by id asc" openstreetmap > $T/users_disagreed if cmp -s "${T}/users_agreed" "/store/planet/users_agreed/users_agreed.txt"; then : # do nothing diff --git a/cookbooks/planet/templates/default/changesets.conf.erb b/cookbooks/planet/templates/default/changesets.conf.erb index f35e403fe..309f253b4 100644 --- a/cookbooks/planet/templates/default/changesets.conf.erb +++ b/cookbooks/planet/templates/default/changesets.conf.erb @@ -1,3 +1,3 @@ state_file: /store/planet/replication/changesets/state.yaml -db: host=katla.bm.openstreetmap.org dbname=openstreetmap user=planetdiff password=<%= @password %> +db: host=<%= node[:web][:database_host] %> dbname=openstreetmap user=planetdiff password=<%= @password %> data_dir: /store/planet/replication/changesets diff --git a/cookbooks/planet/templates/default/replication.auth.erb b/cookbooks/planet/templates/default/replication.auth.erb index bcba0e486..e80dd23d0 100644 --- a/cookbooks/planet/templates/default/replication.auth.erb +++ b/cookbooks/planet/templates/default/replication.auth.erb @@ -1,7 +1,7 @@ # DO NOT EDIT - This file is being maintained by Chef # The database host system -host=katla.bm.openstreetmap.org +host=<%= node[:web][:database_host] %> # The database instance database=openstreetmap diff --git a/cookbooks/planet/templates/default/users-agreed.conf.erb b/cookbooks/planet/templates/default/users-agreed.conf.erb index 1f2e3c36c..29fe1a55f 100644 --- a/cookbooks/planet/templates/default/users-agreed.conf.erb +++ b/cookbooks/planet/templates/default/users-agreed.conf.erb @@ -1,3 +1,3 @@ # DO NOT EDIT - This file is being maintained by Chef -ramoth.ic.openstreetmap.org:5432:openstreetmap:planetdiff:<%= @password %> +<%= node[:web][:readonly_database_host] %>:5432:openstreetmap:planetdiff:<%= @password %> diff --git a/roles/planet.rb b/roles/planet.rb index d68bdabc3..8ee1ce9e9 100644 --- a/roles/planet.rb +++ b/roles/planet.rb @@ -43,6 +43,7 @@ default_attributes( ) run_list( + "role[web-db]", "recipe[planet]", "recipe[planet::replication]", "recipe[nfs::server]", diff --git a/roles/web-db.rb b/roles/web-db.rb new file mode 100644 index 000000000..e394ec2d0 --- /dev/null +++ b/roles/web-db.rb @@ -0,0 +1,9 @@ +name "web-db" +description "Role applied to all servers needing to find the main database" + +default_attributes( + :web => { + :database_host => "katla.bm.openstreetmap.org", + :readonly_database_host => "ramoth.ic.openstreetmap.org" + } +) diff --git a/roles/web.rb b/roles/web.rb index a57d2ec54..85124e485 100644 --- a/roles/web.rb +++ b/roles/web.rb @@ -14,8 +14,10 @@ default_attributes( :pool_idle_time => 0 }, :web => { - :status => "online", - :database_host => "katla.bm.openstreetmap.org", - :readonly_database_host => "ramoth.ic.openstreetmap.org" + :status => "online" } ) + +run_list( + "role[web-db]" +) -- 2.43.2