Skip to content
Snippets Groups Projects
Commit d2b9e77f authored by Ian Baum's avatar Ian Baum Committed by Marin Jankovski
Browse files

Automate repmgrd

parent ade0357e
No related branches found
No related tags found
No related merge requests found
Showing
with 142 additions and 22 deletions
default['repmgr']['cluster'] = 'gitlab_cluster'
default['repmgr']['database'] = 'gitlab_repmgr'
default['repmgr']['failover'] = 'automatic'
default['repmgr']['host'] = nil
default['repmgr']['log_directory'] = '/var/log/gitlab/repmgrd'
default['repmgr']['node_number'] = nil
default['repmgr']['port'] = 5432
default['repmgr']['trust_auth_cidr_addresses'] = []
default['repmgr']['user'] = 'gitlab_repmgr'
default['repmgr']['daemon'] = true
default['repmgr']['service_start_command'] = '/opt/gitlab/bin/gitlab-ctl start postgresql'
default['repmgr']['service_stop_command'] = '/opt/gitlab/bin/gitlab-ctl stop postgresql'
default['repmgr']['service_restart_command'] = '/opt/gitlab/bin/gitlab-ctl restart postgresql'
default['repmgr']['promote_command'] = '/opt/gitlab/embedded/bin/repmgr standby promote -f /var/opt/gitlab/postgresql/repmgr.conf'
default['repmgr']['follow_command'] = '/opt/gitlab/embedded/bin/repmgr standby follow -f /var/opt/gitlab/postgresql/repmgr.conf'
Loading
Loading
@@ -9,3 +9,6 @@ chef_version '>= 12.1' if respond_to?(:chef_version)
 
issues_url 'https://gitlab.com/gitlab-org/omnibus-gitlab/issues'
source_url 'https://gitlab.com/gitlab-org/omnibus-gitlab'
depends 'runit'
depends 'gitlab'
Loading
Loading
@@ -15,6 +15,4 @@
# limitations under the License.
#
 
runit_service 'repmgr' do
action :disable
end
include_recipe 'repmgr::disable_daemon'
#
# Copyright:: Copyright (c) 2017 GitLab Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
runit_service 'repmgrd' do
action :disable
end
Loading
Loading
@@ -13,11 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
account_helper = AccountHelper.new(node)
repmgr_helper = RepmgrHelper.new(node)
replication_user = node['repmgr']['user']
repmgr_conf = "#{node['gitlab']['postgresql']['dir']}/repmgr.conf"
 
log_directory = node['repmgr']['log_directory']
node.default['gitlab']['postgresql']['custom_pg_hba_entries']['repmgr'] = repmgr_helper.pg_hba_entries
 
# node number needs to be unique (to the cluster) positive 32 bit integer.
Loading
Loading
@@ -26,7 +29,7 @@ node_number = node['repmgr']['node_number'] ||
Digest::MD5.hexdigest(node['fqdn']).unpack('L').first
template repmgr_conf do
source 'repmgr.conf.erb'
owner node['gitlab']['postgresql']['username']
owner account_helper.postgresql_user
variables(
node['repmgr'].to_hash.merge(
node_name: node['repmgr']['node_name'] || node['fqdn'],
Loading
Loading
@@ -47,6 +50,17 @@ end
 
execute 'register repmgr master node' do
command "/opt/gitlab/embedded/bin/repmgr -f #{repmgr_conf} master register"
user node['gitlab']['postgresql']['username']
user account_helper.postgresql_user
action :nothing
end
directory log_directory do
owner account_helper.postgresql_user
mode '0700'
end
if node['repmgr']['daemon']
include_recipe 'repmgr::enable_daemon'
else
include_recipe 'repmgr::disable_daemon'
end
#
# Copyright:: Copyright (c) 2017 GitLab Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
account_helper = AccountHelper.new(node)
log_directory = node['repmgr']['log_directory']
runit_service 'repmgrd' do
supervisor_owner account_helper.postgresql_user
supervisor_group account_helper.postgresql_user
options({
log_directory: log_directory,
}.merge(params))
log_options node['gitlab']['logging'].to_hash.merge(node['repmgr'].to_hash)
end
Loading
Loading
@@ -3,8 +3,11 @@ node=<%= @node_number %>
node_name=<%= @node_name %>
conninfo='host=<%= @host %> port=<%= @port %> user=<%= @user %> dbname=<%= @database %>'
pg_bindir='/opt/gitlab/embedded/bin'
service_start_command = '/opt/gitlab/bin/gitlab-ctl start postgresql'
service_stop_command = '/opt/gitlab/bin/gitlab-ctl stop postgresql'
service_restart_command = '/opt/gitlab/bin/gitlab-ctl restart postgresql'
promote_command = '/opt/gitlab/embedded/bin/repmgr standby promote -f /var/opt/gitlab/postgresql/repmgr.conf'
follow_command = '/opt/gitlab/embedded/bin/repmgr standby follow -f /var/opt/gitlab/postgresql/repmgr.conf'
service_start_command = <%= @service_start_command %>
service_stop_command = <%= @service_stop_command %>
service_restart_command = <%= @service_restart_command %>
promote_command = <%= @promote_command %>
follow_command = <%= @follow_command %>
<% if @daemon%>
failover = <%= @failover %>
<% end %>
<%= "s#@svlogd_size" if @svlogd_size %>
<%= "n#@svlogd_num" if @svlogd_num %>
<%= "t#@svlogd_timeout" if @svlogd_timeout %>
<%= "!#@svlogd_filter" if @svlogd_filter %>
<%= "u#@svlogd_udp" if @svlogd_udp %>
<%= "p#@svlogd_prefix" if @svlogd_prefix %>
#!/bin/sh
exec svlogd -tt <%= @options[:log_directory] %>
#!/bin/bash
set -e # fail on errors
# Redirect stderr -> stdout
exec 2>&1
cd <%= node['gitlab']['postgresql']['dir'] %>
exec chpst -P \
-U <%= node['gitlab']['postgresql']['username'] %>:<%= node['gitlab']['postgresql']['username'] %> \
-u <%= node['gitlab']['postgresql']['username'] %>:<%= node['gitlab']['postgresql']['username'] %> \
/opt/gitlab/embedded/bin/repmgrd -f /var/opt/gitlab/postgresql/repmgr.conf --verbose >> <%= node['repmgr']['log_directory'] %>/repmgrd.log
Loading
Loading
@@ -17,11 +17,12 @@ node=1647392869
node_name=fauxhai.local
conninfo='host=fauxhai.local port=5432 user=gitlab_repmgr dbname=gitlab_repmgr'
pg_bindir='/opt/gitlab/embedded/bin'
service_start_command = '/opt/gitlab/bin/gitlab-ctl start postgresql'
service_stop_command = '/opt/gitlab/bin/gitlab-ctl stop postgresql'
service_restart_command = '/opt/gitlab/bin/gitlab-ctl restart postgresql'
promote_command = '/opt/gitlab/embedded/bin/repmgr standby promote -f /var/opt/gitlab/postgresql/repmgr.conf'
follow_command = '/opt/gitlab/embedded/bin/repmgr standby follow -f /var/opt/gitlab/postgresql/repmgr.conf'
service_start_command = /opt/gitlab/bin/gitlab-ctl start postgresql
service_stop_command = /opt/gitlab/bin/gitlab-ctl stop postgresql
service_restart_command = /opt/gitlab/bin/gitlab-ctl restart postgresql
promote_command = /opt/gitlab/embedded/bin/repmgr standby promote -f /var/opt/gitlab/postgresql/repmgr.conf
follow_command = /opt/gitlab/embedded/bin/repmgr standby follow -f /var/opt/gitlab/postgresql/repmgr.conf
failover = automatic
EOF
end
 
Loading
Loading
@@ -29,10 +30,23 @@ follow_command = '/opt/gitlab/embedded/bin/repmgr standby follow -f /var/opt/git
allow(Gitlab).to receive(:[]).and_call_original
end
 
context 'disabled by default' do
# TODO: uncomment once we are automating repmgrd
# it_behaves_like 'disabled runit service', 'repmgrd'
context 'disable_daemon' do
let(:chef_run) { ChefSpec::SoloRunner.converge('repmgr::disable_daemon') }
it_behaves_like 'disabled runit service', 'repmgrd'
end
context 'enable_daemon' do
let(:chef_run) { ChefSpec::SoloRunner.converge('repmgr::enable_daemon') }
it_behaves_like 'enabled runit service', 'repmgrd', 'root', 'root'
end
context 'disable' do
it 'should include the repmgr::disable_daemon recipe' do
expect(chef_run).to include_recipe('repmgr::disable_daemon')
end
end
 
context 'disabled by default' do
it 'should include the repmgr::disable recipe' do
expect(chef_run).to include_recipe('repmgr::disable')
end
Loading
Loading
@@ -57,14 +71,15 @@ follow_command = '/opt/gitlab/embedded/bin/repmgr standby follow -f /var/opt/git
)
end
 
# TODO: uncomment once we are automating repmgrd
# it_behaves_like 'enabled runit service', 'repmgrd'
context 'by default' do
it 'includes the repmgr::enable recipe' do
expect(chef_run).to include_recipe('repmgr::enable')
end
 
it 'should include the repmgr::enable_daemon recipe' do
expect(chef_run).to include_recipe('repmgr::enable_daemon')
end
it 'sets up the repmgr specific entries in pg_hba.conf' do
expect(chef_run).to render_file('/var/opt/gitlab/postgresql/data/pg_hba.conf')
.with_content { |content|
Loading
Loading
@@ -165,5 +180,18 @@ follow_command = '/opt/gitlab/embedded/bin/repmgr standby follow -f /var/opt/git
)
end
end
context 'user disabled the daemon' do
before do
stub_gitlab_rb(
repmgr: {
enable: true,
daemon: false
}
)
end
it_behaves_like 'disabled runit service', 'repmgrd'
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment