Commit d2ef8b46 authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Alain Takoudjou

NXD lib/tasks/gitlab/check: Exit with non-zero code, if something failed in a check task

This is handy for monitoring tools, which could e.g. periodically call check
tasks and instead of parsing output, rely on exit code.

The way we detect if something failed is via hooking into String#red, and if
anything was ever printed in red - that's an error.
parent faafaa98
# if we ever print anything in red - that's an error
$check_failed = false
class String
alias_method :orig_color, :color
def color(code)
if code == :red
$check_failed = true
end
orig_color(code)
end
end
namespace :gitlab do namespace :gitlab do
desc "GitLab | Check the configuration of GitLab and its environment" desc "GitLab | Check the configuration of GitLab and its environment"
task check: %w{gitlab:gitlab_shell:check task check: %w{gitlab:gitlab_shell:check
...@@ -866,8 +878,9 @@ namespace :gitlab do ...@@ -866,8 +878,9 @@ namespace :gitlab do
def finished_checking(component) def finished_checking(component)
puts "" puts ""
puts "Checking #{component.color(:yellow)} ... #{"Finished".color(:green)}" puts "Checking #{component.color(:yellow)} ... #{$check_failed ? "Failed"color(:red) : "OK".color(:green)}"
puts "" puts ""
exit 1 if $check_failed
end end
def see_database_guide def see_database_guide
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment