-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
144 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Checks | ||
module ContainerGateway | ||
class DBUp < ForemanMaintain::Check | ||
metadata do | ||
description 'Make sure ContainerGateway DB is up' | ||
label :container_gateway_db_up | ||
for_feature :container_gateway_database | ||
end | ||
|
||
def run | ||
status = false | ||
with_spinner('Checking connection to the Container Gateway DB') do | ||
status = feature(:container_gateway_database).ping | ||
end | ||
assert(status, 'Container Gateway DB is not responding. ' \ | ||
'It needs to be up and running to perform the following steps', | ||
:next_steps => next_steps) | ||
end | ||
|
||
def next_steps | ||
if feature(:container_gateway_database).local? | ||
[Procedures::Service::Start.new(:only => 'postgresql')] | ||
else | ||
[] # there is nothing we can do for remote db | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class Features::ContainerGatewayDatabase < ForemanMaintain::Feature | ||
CONTAINER_GATEWAY_DB_CONFIG = '/etc/foreman-proxy/settings.d/container_gateway.yml'.freeze | ||
|
||
include ForemanMaintain::Concerns::BaseDatabase | ||
include ForemanMaintain::Concerns::DirectoryMarker | ||
|
||
metadata do | ||
label :container_gateway_database | ||
|
||
confine do | ||
file_nonzero?(CONTAINER_GATEWAY_DB_CONFIG) | ||
end | ||
end | ||
|
||
def configuration | ||
@configuration || load_configuration | ||
end | ||
|
||
def services | ||
[ | ||
system_service('postgresql', 10, :component => 'container_gateway', | ||
:db_feature => feature(:container_gateway_database)), | ||
] | ||
end | ||
|
||
private | ||
|
||
def load_configuration | ||
config = YAML.load(File.read(CONTAINER_GATEWAY_DB_CONFIG)) | ||
@configuration = {} | ||
connection_string = config[:db_connection_string] | ||
if connection_string | ||
uri = URI.parse(connection_string) | ||
@configuration['adapter'] = uri.scheme | ||
@configuration['host'] = uri.host | ||
@configuration['port'] = uri.port | ||
@configuration['database'] = uri.path[1..-1] | ||
@configuration['username'] = uri.user | ||
@configuration['password'] = uri.password | ||
end | ||
@configuration | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
definitions/procedures/backup/online/container_gateway_db.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Procedures::Backup | ||
module Online | ||
class ContainerGatewayDB < ForemanMaintain::Procedure | ||
metadata do | ||
description 'Backup Container Gateway database' | ||
tags :backup | ||
label :backup_online_container_gateway_db | ||
for_feature :container_gateway_database | ||
preparation_steps { Checks::ContainerGateway::DBUp.new } | ||
param :backup_dir, 'Directory where to backup to', :required => true | ||
end | ||
|
||
def run | ||
with_spinner('Getting Container Gateway DB dump') do | ||
feature(:container_gateway_database).dump_db(File.join(@backup_dir, 'container_gateway.dump')) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Procedures::Restore | ||
class ContainerGatewayDump < ForemanMaintain::Procedure | ||
metadata do | ||
description 'Restore container gateway postgresql dump from backup' | ||
param :backup_dir, | ||
'Path to backup directory', | ||
:required => true | ||
preparation_steps { Checks::ContainerGateway::DBUp.new } | ||
confine do | ||
feature(:container_gateway_database) | ||
end | ||
end | ||
|
||
def run | ||
backup = ForemanMaintain::Utils::Backup.new(@backup_dir) | ||
|
||
with_spinner('Restoring container gateway postgresql dump') do |spinner| | ||
restore_container_gateway_dump(backup, spinner) | ||
end | ||
end | ||
|
||
def restore_container_gateway_dump(backup, spinner) | ||
if backup.file_map[:container_gateway_dump][:present] | ||
spinner.update('Restoring container gateway dump') | ||
local = feature(:container_gateway_database).local? | ||
feature(:container_gateway_database).restore_dump(backup.file_map[:container_gateway_dump][:path], local) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters