Skip to content
Snippets Groups Projects
Commit 302b778d authored by Gabriel Mazetto's avatar Gabriel Mazetto :spy_tone1:
Browse files

Added gitlab-pg-ctl and using promote instead of touch pg trigger file

This is a better way to promote a following database into primary
parent 988d7113
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -86,6 +86,7 @@ if ee
dependency 'consul'
dependency 'gitlab-ctl-ee'
dependency 'gitlab-geo-psql'
dependency 'gitlab-pg-ctl'
end
dependency 'gitlab-ctl'
dependency 'gitlab-psql'
Loading
Loading
#
# Copyright:: Copyright (c) 2018 GitLab Inc.
# License:: Apache License, Version 2.0
#
# 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.
#
require 'digest'
name 'gitlab-pg-ctl'
license 'Apache-2.0'
license_file File.expand_path('LICENSE', Omnibus::Config.project_root)
# This 'software' is self-contained in this file. Use the file contents
# to generate a version string.
default_version Digest::MD5.file(__FILE__).hexdigest
build do
block do
open("#{install_dir}/embedded/bin/gitlab-pg-ctl", 'w') do |file|
file.print <<-EOH
#!/bin/sh
error_echo()
{
echo "$1" 2>& 1
}
gitlab_psql_rc='/opt/gitlab/etc/gitlab-psql-rc'
if ! [ -f ${gitlab_psql_rc} ] || ! [ -r ${gitlab_psql_rc} ] ; then
error_echo "$0 error: could not load ${gitlab_psql_rc}"
error_echo "Either you are not allowed to read the file, or it does not exist yet."
error_echo "You can generate it with: sudo gitlab-ctl reconfigure"
exit 1
fi
. "${gitlab_psql_rc}"
if [ "$(id -n -u)" = "${psql_user}" ] ; then
privilege_drop=''
else
privilege_drop="-u ${psql_user}"
fi
export PGDATA=${psql_host}/data
exec /opt/gitlab/embedded/bin/chpst "${privilege_drop}" /opt/gitlab/embedded/bin/pg_ctl "$@"
EOH
end
end
command "chmod 755 #{install_dir}/embedded/bin/gitlab-pg-ctl"
end
Loading
Loading
@@ -3,8 +3,6 @@ require 'rainbow/ext/string'
 
module Geo
class PromoteToPrimary
TRIGGER_FILE_PATH = '/tmp/postgresql.trigger'.freeze
def initialize(base_path, options)
@base_path = base_path
@options = options
Loading
Loading
@@ -35,7 +33,7 @@ module Geo
puts '---------------------------------------'.color(:yellow)
puts 'WARNING: Make sure your primary is down and also be aware that'.color(:yellow)
puts 'this command only works for setups with one secondary.'.color(:yellow)
puts 'If you have more of them please see https://docs.gitlab.com/ee/gitlab-geo/disaster-recovery.md#promoting-secondary-geo-replica-in-multi-secondary-configurations'.color(:yellow)
puts 'If you have more of them please see https://docs.gitlab.com/ee/gitlab-geo/disaster-recovery.html#promoting-secondary-geo-replica-in-multi-secondary-configurations'.color(:yellow)
puts 'There may be data saved to the primary that was not been replicated to the secondary before the primary went offline. This data should be treated as lost if you proceed.'.color(:yellow)
puts '---------------------------------------'.color(:yellow)
puts
Loading
Loading
@@ -47,10 +45,10 @@ module Geo
 
def promote_postgresql_to_primary
puts
puts 'Promoting the Postgres to primary...'.color(:yellow)
puts 'Promoting the PostgreSQL to primary...'.color(:yellow)
puts
 
run_command("touch #{TRIGGER_FILE_PATH}")
run_command("/opt/gitlab/embedded/bin/gitlab-pg-ctl promote")
end
 
def remove_ssh_keys
Loading
Loading
Loading
Loading
@@ -139,7 +139,6 @@ module Geo
file.write(<<~EOF
standby_mode = 'on'
primary_conninfo = 'host=#{@options[:host]} port=#{@options[:port]} user=#{@options[:user]} password=#{@options[:password]} sslmode=#{@options[:sslmode]}'
trigger_file = '/tmp/postgresql.trigger'
EOF
)
file.write("primary_slot_name = '#{@options[:slot_name]}'\n") if @options[:slot_name]
Loading
Loading
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