Output logs when healthcheck fails

This commit is contained in:
David Heinemeier Hansson
2023-02-19 09:33:49 +01:00
parent e37e5f7d09
commit 8e918b1906
2 changed files with 11 additions and 6 deletions

View File

@@ -21,6 +21,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
raise
end
ensure
error capture_with_info(*MRSK.healthcheck.logs)
execute *MRSK.healthcheck.stop, raise_on_non_zero_exit: false
execute *MRSK.healthcheck.remove, raise_on_non_zero_exit: false
end

View File

@@ -19,16 +19,16 @@ class Mrsk::Commands::Healthcheck < Mrsk::Commands::Base
[ :curl, "--silent", "--output", "/dev/null", "--write-out", "'%{http_code}'", health_url ]
end
def logs
pipe container_id, xargs(docker(:logs, "2>&1"))
end
def stop
pipe \
container_id_for(container_name: container_name),
xargs(docker(:stop))
pipe container_id, xargs(docker(:stop))
end
def remove
pipe \
container_id_for(container_name: container_name),
xargs(docker(:container, :rm))
pipe container_id, xargs(docker(:container, :rm))
end
private
@@ -40,6 +40,10 @@ class Mrsk::Commands::Healthcheck < Mrsk::Commands::Base
"healthcheck-#{config.service_with_version}"
end
def container_id
container_id_for(container_name: container_name)
end
def health_url
"http://localhost:#{EXPOSED_PORT}#{config.healthcheck["path"]}"
end