Merge branch 'rake-gitaly-check' into 'master'

Delegate storage health check to Gitaly's health check

Closes gitaly#1336

See merge request gitlab-org/gitlab-ce!22063
This commit is contained in:
Rémy Coutable 2018-11-06 15:08:32 +00:00
commit e232ebf7a1
3 changed files with 29 additions and 118 deletions

View file

@ -0,0 +1,5 @@
---
title: Add gitlab:gitaly:check task for Gitaly health check
merge_request: 22063
author:
type: other

View file

@ -53,6 +53,7 @@ Git: /usr/bin/git
Runs the following rake tasks:
- `gitlab:gitlab_shell:check`
- `gitlab:gitaly:check`
- `gitlab:sidekiq:check`
- `gitlab:app:check`
@ -252,7 +253,7 @@ clear it.
To clear all exclusive leases:
DANGER: **DANGER**:
DANGER: **DANGER**:
Don't run it while GitLab or Sidekiq is running
```bash

View file

@ -1,6 +1,7 @@
namespace :gitlab do
desc 'GitLab | Check the configuration of GitLab and its environment'
task check: %w{gitlab:gitlab_shell:check
gitlab:gitaly:check
gitlab:sidekiq:check
gitlab:incoming_email:check
gitlab:ldap:check
@ -44,13 +45,7 @@ namespace :gitlab do
start_checking "GitLab Shell"
check_gitlab_shell
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
check_repo_base_exists
check_repo_base_is_not_symlink
check_repo_base_user_and_group
check_repo_base_permissions
check_repos_hooks_directory_is_link
end
check_repos_hooks_directory_is_link
check_gitlab_shell_self_test
finished_checking "GitLab Shell"
@ -59,116 +54,6 @@ namespace :gitlab do
# Checks
########################
def check_repo_base_exists
puts "Repo base directory exists?"
Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage.legacy_disk_path
print "#{name}... "
if File.exist?(repo_base_path)
puts "yes".color(:green)
else
puts "no".color(:red)
puts "#{repo_base_path} is missing".color(:red)
try_fixing_it(
"This should have been created when setting up GitLab Shell.",
"Make sure it's set correctly in config/gitlab.yml",
"Make sure GitLab Shell is installed correctly."
)
for_more_information(
see_installation_guide_section "GitLab Shell"
)
fix_and_rerun
end
end
end
def check_repo_base_is_not_symlink
puts "Repo storage directories are symlinks?"
Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage.legacy_disk_path
print "#{name}... "
unless File.exist?(repo_base_path)
puts "can't check because of previous errors".color(:magenta)
break
end
unless File.symlink?(repo_base_path)
puts "no".color(:green)
else
puts "yes".color(:red)
try_fixing_it(
"Make sure it's set to the real directory in config/gitlab.yml"
)
fix_and_rerun
end
end
end
def check_repo_base_permissions
puts "Repo paths access is drwxrws---?"
Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage.legacy_disk_path
print "#{name}... "
unless File.exist?(repo_base_path)
puts "can't check because of previous errors".color(:magenta)
break
end
if File.stat(repo_base_path).mode.to_s(8).ends_with?("2770")
puts "yes".color(:green)
else
puts "no".color(:red)
try_fixing_it(
"sudo chmod -R ug+rwX,o-rwx #{repo_base_path}",
"sudo chmod -R ug-s #{repo_base_path}",
"sudo find #{repo_base_path} -type d -print0 | sudo xargs -0 chmod g+s"
)
for_more_information(
see_installation_guide_section "GitLab Shell"
)
fix_and_rerun
end
end
end
def check_repo_base_user_and_group
gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user
puts "Repo paths owned by #{gitlab_shell_ssh_user}:root, or #{gitlab_shell_ssh_user}:#{Gitlab.config.gitlab_shell.owner_group}?"
Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage.legacy_disk_path
print "#{name}... "
unless File.exist?(repo_base_path)
puts "can't check because of previous errors".color(:magenta)
break
end
user_id = uid_for(gitlab_shell_ssh_user)
root_group_id = gid_for('root')
group_ids = [root_group_id, gid_for(Gitlab.config.gitlab_shell.owner_group)]
if File.stat(repo_base_path).uid == user_id && group_ids.include?(File.stat(repo_base_path).gid)
puts "yes".color(:green)
else
puts "no".color(:red)
puts " User id for #{gitlab_shell_ssh_user}: #{user_id}. Groupd id for root: #{root_group_id}".color(:blue)
try_fixing_it(
"sudo chown -R #{gitlab_shell_ssh_user}:root #{repo_base_path}"
)
for_more_information(
see_installation_guide_section "GitLab Shell"
)
fix_and_rerun
end
end
end
def check_repos_hooks_directory_is_link
print "hooks directories in repos are links: ... "
@ -247,6 +132,26 @@ namespace :gitlab do
end
end
namespace :gitaly do
desc 'GitLab | Check the health of Gitaly'
task check: :gitlab_environment do
warn_user_is_not_gitlab
start_checking 'Gitaly'
Gitlab::HealthChecks::GitalyCheck.readiness.each do |result|
print "#{result.labels[:shard]} ... "
if result.success
puts 'OK'.color(:green)
else
puts "FAIL: #{result.message}".color(:red)
end
end
finished_checking 'Gitaly'
end
end
namespace :sidekiq do
desc "GitLab | Check the configuration of Sidekiq"
task check: :gitlab_environment do