diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index 634a9d0..053b232 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -26,7 +26,6 @@ include_recipe "kosmos-nodejs" include_recipe "kosmos-redis" -include_recipe "kosmos-postgresql" include_recipe "java" elasticsearch_user 'elasticsearch' @@ -42,22 +41,11 @@ end elasticsearch_service 'elasticsearch' -# TODO: Remove the condition once we have migrated mastodon to andromeda -unless platform?('ubuntu') && node[:platform_version].to_f < 18.04 - postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') - - postgresql_user 'mastodon' do - action :create - password postgresql_data_bag_item['mastodon_user_password'] - end - - postgresql_database 'mastodon' do - owner 'mastodon' - action :create - end -else - postgresql_data_bag_item = {} -end +postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') +postgresql_primary_node = postgresql_primary +postgresql_server = postgresql_primary_node[:ipaddress] +# PostgreSQL is on the same server, connect through localhost +postgresql_server = "localhost" if postgresql_primary_node[:hostname] == node[:hostname] mastodon_path = node["kosmos-mastodon"]["directory"] @@ -169,7 +157,8 @@ application mastodon_path do s3_region: "eu-west-1", vapid_private_key: mastodon_credentials['vapid_private_key'], vapid_public_key: mastodon_credentials['vapid_public_key'], - db_pass: postgresql_data_bag_item['mastodon_user_password'] + db_pass: postgresql_data_bag_item['mastodon_user_password'], + db_host: postgresql_server end execute "bundle install" do @@ -214,18 +203,3 @@ application mastodon_path do action [:enable, :start] end end - -# -# Backup -# - -unless node.chef_environment == "development" - unless node["backup"]["postgresql"]["databases"].keys.include? 'mastodon' - node.override["backup"]["postgresql"]["databases"]["mastodon"] = { - username: "mastodon", - password: postgresql_data_bag_item['mastodon_user_password'] - } - end - - include_recipe "backup" -end diff --git a/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb b/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb new file mode 100644 index 0000000..4f0ee9f --- /dev/null +++ b/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb @@ -0,0 +1,52 @@ +# +# Cookbook Name:: kosmos-mastodon +# Recipe:: pg_db +# +# The MIT License (MIT) +# +# Copyright:: 2020, Kosmos Developers +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') + +postgresql_user 'mastodon' do + action :create + password postgresql_data_bag_item['mastodon_user_password'] +end + +postgresql_database 'mastodon' do + owner 'mastodon' + action :create +end + +# +# Backup +# + +unless node.chef_environment == "development" + unless node["backup"]["postgresql"]["databases"].keys.include? 'mastodon' + node.override["backup"]["postgresql"]["databases"]["mastodon"] = { + username: "mastodon", + password: postgresql_data_bag_item['mastodon_user_password'] + } + end + + include_recipe "backup" +end diff --git a/site-cookbooks/kosmos-mastodon/templates/default/env.production.erb b/site-cookbooks/kosmos-mastodon/templates/default/env.production.erb index eb3b559..7cb7adc 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/env.production.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/env.production.erb @@ -1,15 +1,9 @@ # Service dependencies REDIS_URL=<%= @redis_url %> -DB_HOST=localhost +DB_HOST=<%= @db_host %> DB_NAME=mastodon -# TODO: Remove the condition once we have migrated mastodon to andromeda -<% if node[:platform_version].to_f < 18.04 -%> -DB_USER=postgres -DB_PASS=<%= node['postgresql']['password']['postgres'] %> -<% else -%> DB_USER=mastodon DB_PASS=<%= @db_pass %> -<% end -%> DB_PORT=5432 # Federation diff --git a/site-cookbooks/kosmos-mastodon/templates/default/mastodon-web.systemd.service.erb b/site-cookbooks/kosmos-mastodon/templates/default/mastodon-web.systemd.service.erb index 94a6346..2fedefa 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/mastodon-web.systemd.service.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/mastodon-web.systemd.service.erb @@ -2,8 +2,6 @@ Description=mastodon-web Requires=redis-server.service After=redis-server.service -Requires=postgresql@9.4-main.service -After=postgresql@9.4-main.service [Service] Type=simple