Commit 098c7225 authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Add gitlab:gitaly:check task for Gitaly health check

Also, since Gitaly now takes care of checking for storage paths
existence/accessibility, we can remove those check from the
gitlab:gitlab_shell_check task and advance further into 0 direct disk
approach on gitlab-rails
parent 742f8d64
---
title: Add gitlab:gitaly:check task for Gitaly health check
merge_request: 22063
author:
type: other
...@@ -53,6 +53,7 @@ Git: /usr/bin/git ...@@ -53,6 +53,7 @@ Git: /usr/bin/git
Runs the following rake tasks: Runs the following rake tasks:
- `gitlab:gitlab_shell:check` - `gitlab:gitlab_shell:check`
- `gitlab:gitaly:check`
- `gitlab:sidekiq:check` - `gitlab:sidekiq:check`
- `gitlab:app:check` - `gitlab:app:check`
...@@ -252,7 +253,7 @@ clear it. ...@@ -252,7 +253,7 @@ clear it.
To clear all exclusive leases: To clear all exclusive leases:
DANGER: **DANGER**: DANGER: **DANGER**:
Don't run it while GitLab or Sidekiq is running Don't run it while GitLab or Sidekiq is running
```bash ```bash
......
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
gitlab:gitaly:check
gitlab:sidekiq:check gitlab:sidekiq:check
gitlab:incoming_email:check gitlab:incoming_email:check
gitlab:ldap:check gitlab:ldap:check
...@@ -44,13 +45,7 @@ namespace :gitlab do ...@@ -44,13 +45,7 @@ namespace :gitlab do
start_checking "GitLab Shell" start_checking "GitLab Shell"
check_gitlab_shell check_gitlab_shell
Gitlab::GitalyClient::StorageSettings.allow_disk_access do check_repos_hooks_directory_is_link
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_gitlab_shell_self_test check_gitlab_shell_self_test
finished_checking "GitLab Shell" finished_checking "GitLab Shell"
...@@ -59,116 +54,6 @@ namespace :gitlab do ...@@ -59,116 +54,6 @@ namespace :gitlab do
# Checks # 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 def check_repos_hooks_directory_is_link
print "hooks directories in repos are links: ... " print "hooks directories in repos are links: ... "
...@@ -247,6 +132,26 @@ namespace :gitlab do ...@@ -247,6 +132,26 @@ namespace :gitlab do
end end
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 namespace :sidekiq do
desc "GitLab | Check the configuration of Sidekiq" desc "GitLab | Check the configuration of Sidekiq"
task check: :gitlab_environment do task check: :gitlab_environment do
......
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