Commit 0478f717 authored by Valery Sizov's avatar Valery Sizov Committed by Nick Thomas

Add a rake task to turn a Geo secondary node into a Geo primary node

parent e18207d8
---
title: Add geo:set_secondary_as_primary rake task
merge_request:
author:
type: added
......@@ -30,35 +30,7 @@ You must make the changes in the exact specific order:
```bash
sudo rm ~git/.ssh/id_rsa ~git/.ssh/id_rsa.pub
```
1. Open the interactive rails console: `sudo gitlab-rails console` and execute:
* List your primary node and note down it's id:
```ruby
Gitlab::Geo.primary_node
```
* Remove the old primary node:
```ruby
Gitlab::Geo.primary_node.destroy
```
* List your secondary nodes and note down the id of the one you want to promote:
```ruby
Gitlab::Geo.secondary_nodes
```
* To promote a node with id `2` execute:
```ruby
GeoNode.find(2).update!(primary: true)
```
* Now you have to cleanup your new promoted node by running:
```ruby
Gitlab::Geo.primary_node.oauth_application.destroy!
Gitlab::Geo.primary_node.system_hook.destroy!
```
* To exit the interactive console, type: `exit`
1. Run `sudo gitlab-rake geo:set_secondary_as_primary`
1. Rsync everything in `/var/opt/gitlab/gitlab-rails/uploads` and
`/var/opt/gitlab/gitlab-rails/shared` from your old node to the new one.
......
......@@ -151,6 +151,29 @@ namespace :geo do
set_primary_geo_node
end
desc 'Make this secondary node the primary'
task set_secondary_as_primary: :environment do
abort 'GitLab Geo is not supported with this license. Please contact sales@gitlab.com.' unless Gitlab::Geo.license_allows?
ActiveRecord::Base.transaction do
primary_node = Gitlab::Geo.primary_node
unless primary_node
abort 'The primary is not set'
end
primary_node.destroy
current_node = Gitlab::Geo.current_node
unless current_node.secondary?
abort 'This is not a secondary node'
end
current_node.update!(primary: true)
end
end
def set_primary_geo_node
params = {
schema: Gitlab.config.gitlab.protocol,
......
......@@ -25,4 +25,24 @@ describe 'geo rake tasks' do
expect(node.geo_node_key).to be_nil
end
end
describe 'set_secondary_as_primary task' do
include ::EE::GeoHelpers
let!(:current_node) { create(:geo_node) }
let!(:primary_node) { create(:geo_node, :primary) }
before do
expect(Gitlab::Geo).to receive(:license_allows?).and_return(true)
stub_current_geo_node(current_node)
end
it 'removes primary and sets secondary as primary' do
run_rake_task('geo:set_secondary_as_primary')
expect(current_node.primary?).to be_truthy
expect(GeoNode.count).to eq(1)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment