Class: Dash::Cli::Proxy::LoadbalancerReboot

Inherits:
Object
  • Object
show all
Defined in:
lib/dash/cli/proxy/loadbalancer_reboot.rb

Overview

Replaces the loadbalancer container with one booted from the current configuration. Shared by dash proxy reboot and the drift-detected reboot on boot - the same sequence either way, so the two paths cannot diverge.

Unlike the proxy hosts' port-holder handoff this is stop -> run: the loadbalancer keeps its service state in the config volume, which the replacement container re-mounts, so every app's routes survive the gap.

Constant Summary collapse

READY_TIMEOUT =
30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, sshkit) ⇒ LoadbalancerReboot

Returns a new instance of LoadbalancerReboot.



14
15
16
17
# File 'lib/dash/cli/proxy/loadbalancer_reboot.rb', line 14

def initialize(host, sshkit)
  @host = host
  @sshkit = sshkit
end

Instance Attribute Details

#host ⇒ Object (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/dash/cli/proxy/loadbalancer_reboot.rb', line 11

def host
  @host
end

#sshkit ⇒ Object (readonly)

Returns the value of attribute sshkit.



11
12
13
# File 'lib/dash/cli/proxy/loadbalancer_reboot.rb', line 11

def sshkit
  @sshkit
end

Instance Method Details

#run ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dash/cli/proxy/loadbalancer_reboot.rb', line 19

def run
  execute *DASH.auditor.record("Rebooted loadbalancer"), verbosity: :debug
  execute *DASH.registry.
  ensure_network

  # After the network the bridge attaches the legacy network's containers to,
  # and before anything that could create the new container or let `docker
  # run --volume` create dash-loadbalancer-config empty: adopt the legacy
  # volume's routing table, dynamic domains and ACME cache. Carries the
  # apps-config mkdir this reboot paid a round trip for anyway
  # (zoolutions/dash#168, see Dash::Commands::Loadbalancer#legacy_rename).
  execute *DASH.loadbalancer.prepare_boot

  info "Stopping and removing #{DASH.loadbalancer.container_name} on #{host}, if running..."
  execute *DASH.loadbalancer.stop, raise_on_non_zero_exit: false
  execute *DASH.loadbalancer.remove_container

  if (lb_run = DASH.loadbalancer_config.run).secrets?
    execute *DASH.loadbalancer.ensure_proxy_directory
    upload! lb_run.secrets_io, lb_run.secrets_path, mode: "0600"
  else
    execute *DASH.loadbalancer.remove_proxy_secrets_file, raise_on_non_zero_exit: false
  end

  Dash::Cli::Proxy::LoadbalancerClaim.new(host, sshkit).claim_run_config(replace: true)
  execute *DASH.loadbalancer.run

  wait_until_ready
  verify_service if re_register_service

  # dash-proxy keeps its service state in the config volume, which the
  # replacement container re-mounts - every app's routes survive.
  services = capture_with_info(*DASH.loadbalancer.list).strip
  info "Services registered on the load balancer at #{host} after reboot:\n#{services}"
end