Class: ActivePostgres::Installer
- Inherits:
-
Object
- Object
- ActivePostgres::Installer
- Includes:
- ComponentResolver
- Defined in:
- lib/active_postgres/installer.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#dry_run ⇒ Object
readonly
Returns the value of attribute dry_run.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#rollback_manager ⇒ Object
readonly
Returns the value of attribute rollback_manager.
-
#secrets ⇒ Object
readonly
Returns the value of attribute secrets.
-
#skip_validation ⇒ Object
readonly
Returns the value of attribute skip_validation.
-
#ssh_executor ⇒ Object
readonly
Returns the value of attribute ssh_executor.
-
#use_optimized ⇒ Object
readonly
Returns the value of attribute use_optimized.
Instance Method Summary collapse
-
#initialize(config, dry_run: false, verbose: false, skip_validation: false, use_optimized: true, skip_rollback: false) ⇒ Installer
constructor
A new instance of Installer.
- #list_backups ⇒ Object
- #restart_component(component_name) ⇒ Object
- #run_backup(type) ⇒ Object
- #run_restore(backup_id) ⇒ Object
- #run_restore_at(target_time, target_action: 'promote') ⇒ Object
- #setup ⇒ Object
- #setup_component(component_name) ⇒ Object
- #setup_standby_only(standby_host) ⇒ Object
- #uninstall_component(component_name) ⇒ Object
Methods included from ComponentResolver
Constructor Details
#initialize(config, dry_run: false, verbose: false, skip_validation: false, use_optimized: true, skip_rollback: false) ⇒ Installer
Returns a new instance of Installer.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/active_postgres/installer.rb', line 7 def initialize(config, dry_run: false, verbose: false, skip_validation: false, use_optimized: true, skip_rollback: false) @config = config @dry_run = dry_run @skip_validation = skip_validation @use_optimized = use_optimized @skip_rollback = skip_rollback || ENV['SKIP_ROLLBACK'] == 'true' @ssh_executor = SSHExecutor.new(config) @secrets = Secrets.new(config) @logger = Logger.new(verbose: verbose || ENV['VERBOSE'] == 'true') @rollback_manager = skip_rollback ? nil : RollbackManager.new(config, ssh_executor, logger: logger) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/active_postgres/installer.rb', line 5 def config @config end |
#dry_run ⇒ Object (readonly)
Returns the value of attribute dry_run.
5 6 7 |
# File 'lib/active_postgres/installer.rb', line 5 def dry_run @dry_run end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/active_postgres/installer.rb', line 5 def logger @logger end |
#rollback_manager ⇒ Object (readonly)
Returns the value of attribute rollback_manager.
5 6 7 |
# File 'lib/active_postgres/installer.rb', line 5 def rollback_manager @rollback_manager end |
#secrets ⇒ Object (readonly)
Returns the value of attribute secrets.
5 6 7 |
# File 'lib/active_postgres/installer.rb', line 5 def secrets @secrets end |
#skip_validation ⇒ Object (readonly)
Returns the value of attribute skip_validation.
5 6 7 |
# File 'lib/active_postgres/installer.rb', line 5 def skip_validation @skip_validation end |
#ssh_executor ⇒ Object (readonly)
Returns the value of attribute ssh_executor.
5 6 7 |
# File 'lib/active_postgres/installer.rb', line 5 def ssh_executor @ssh_executor end |
#use_optimized ⇒ Object (readonly)
Returns the value of attribute use_optimized.
5 6 7 |
# File 'lib/active_postgres/installer.rb', line 5 def use_optimized @use_optimized end |
Instance Method Details
#list_backups ⇒ Object
103 104 105 106 |
# File 'lib/active_postgres/installer.rb', line 103 def list_backups component = Components::PgBackRest.new(config, ssh_executor, secrets) component.list_backups end |
#restart_component(component_name) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/active_postgres/installer.rb', line 66 def restart_component(component_name) puts "==> Restarting #{component_name}..." component_class = component_class_for(component_name) component = component_class.new(config, ssh_executor, secrets) component.restart puts "✓ #{component_name} restarted" end |
#run_backup(type) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/active_postgres/installer.rb', line 76 def run_backup(type) puts "==> Running #{type} backup..." component = Components::PgBackRest.new(config, ssh_executor, secrets) component.run_backup(type) puts '✓ Backup complete' end |
#run_restore(backup_id) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/active_postgres/installer.rb', line 85 def run_restore(backup_id) puts "==> Restoring from backup #{backup_id}..." component = Components::PgBackRest.new(config, ssh_executor, secrets) component.run_restore(backup_id) puts '✓ Restore complete' end |
#run_restore_at(target_time, target_action: 'promote') ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/active_postgres/installer.rb', line 94 def run_restore_at(target_time, target_action: 'promote') puts "==> Restoring to #{target_time} (PITR)..." component = Components::PgBackRest.new(config, ssh_executor, secrets) component.run_restore_at(target_time, target_action: target_action) puts '✓ Restore complete' end |
#setup ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_postgres/installer.rb', line 20 def setup logger.warn 'Skipping pre-flight validation (--skip-validation flag)' if skip_validation flow = ClusterDeploymentFlow.new( config, ssh_executor: ssh_executor, secrets: secrets, logger: logger, rollback_manager: rollback_manager, skip_validation: skip_validation ) flow.execute end |
#setup_component(component_name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_postgres/installer.rb', line 34 def setup_component(component_name) logger.task("Setting up #{component_name}") do component_class = component_class_for(component_name) component = component_class.new(config, ssh_executor, secrets) if dry_run logger.info "[DRY RUN] Would setup #{component_name}" else # Register rollback for this component rollback_manager.register("Uninstall #{component_name}", host: nil) do component.uninstall rescue StandardError => e logger.warn "Failed to uninstall #{component_name}: #{e.}" end component.install end logger.success "#{component_name} setup complete" end end |
#setup_standby_only(standby_host) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/active_postgres/installer.rb', line 108 def setup_standby_only(standby_host) logger.warn 'Skipping pre-flight validation (--skip-validation flag)' if skip_validation flow = StandbyDeploymentFlow.new( config, standby_host: standby_host, ssh_executor: ssh_executor, secrets: secrets, logger: logger, rollback_manager: rollback_manager, skip_validation: skip_validation ) flow.execute end |
#uninstall_component(component_name) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/active_postgres/installer.rb', line 56 def uninstall_component(component_name) puts "==> Uninstalling #{component_name}..." component_class = component_class_for(component_name) component = component_class.new(config, ssh_executor, secrets) component.uninstall puts "✓ #{component_name} uninstalled" end |