Merge pull request 'Add PostgreSQL primary server support to the mastodon cookbook' (#187) from feature/186-postgresql_primary_mastodon into master
This commit is contained in:
commit
9ec1fe1db4
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue