Class: Mrsk::Cli::Healthcheck

Inherits:
Base
  • Object
show all
Defined in:
lib/mrsk/cli/healthcheck.rb

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?, #initialize

Constructor Details

This class inherits a constructor from Mrsk::Cli::Base

Instance Method Details

#performObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mrsk/cli/healthcheck.rb', line 3

def perform
  on(MRSK.primary_host) do
    begin
      execute *MRSK.healthcheck.run

      target = "Health check against #{MRSK.config.healthcheck["path"]}"

      if capture_with_info(*MRSK.healthcheck.curl) == "200"
        info "#{target} succeeded with 200 OK!"
      else
        # Catches 1xx, 2xx, 3xx
        raise SSHKit::Command::Failed, "#{target} failed to return 200 OK!"
      end
    rescue SSHKit::Command::Failed => e
      if e.message =~ /curl/
        # Catches 4xx, 5xx
        raise SSHKit::Command::Failed, "#{target} failed to return 200 OK!"
      else
        raise
      end
    ensure
      execute *MRSK.healthcheck.stop, raise_on_non_zero_exit: false
      execute *MRSK.healthcheck.remove, raise_on_non_zero_exit: false
    end
  end
end