2017-05-25 10:16:25 -04:00
|
|
|
# Temporary hack, until we migrate all checks to SystemCheck format
|
|
|
|
require 'system_check'
|
|
|
|
require 'system_check/helpers'
|
|
|
|
|
2012-04-03 18:02:54 -04:00
|
|
|
namespace :gitlab do
|
2017-05-25 10:16:25 -04:00
|
|
|
desc 'GitLab | Check the configuration of GitLab and its environment'
|
2015-06-03 05:26:57 -04:00
|
|
|
task check: %w{gitlab:gitlab_shell:check
|
2013-01-09 18:08:15 -05:00
|
|
|
gitlab:sidekiq:check
|
2015-09-21 03:46:47 -04:00
|
|
|
gitlab:incoming_email:check
|
2013-11-28 09:20:40 -05:00
|
|
|
gitlab:ldap:check
|
2012-12-13 06:11:41 -05:00
|
|
|
gitlab:app:check}
|
|
|
|
|
2012-04-03 18:02:54 -04:00
|
|
|
namespace :app do
|
2017-05-25 10:16:25 -04:00
|
|
|
desc 'GitLab | Check the configuration of the GitLab Rails app'
|
2012-12-10 08:50:55 -05:00
|
|
|
task check: :environment do
|
2012-12-13 06:11:41 -05:00
|
|
|
warn_user_is_not_gitlab
|
|
|
|
|
2017-05-25 10:16:25 -04:00
|
|
|
checks = [
|
|
|
|
SystemCheck::App::GitConfigCheck,
|
|
|
|
SystemCheck::App::DatabaseConfigExistsCheck,
|
|
|
|
SystemCheck::App::MigrationsAreUpCheck,
|
|
|
|
SystemCheck::App::OrphanedGroupMembersCheck,
|
|
|
|
SystemCheck::App::GitlabConfigExistsCheck,
|
2017-05-30 13:06:58 -04:00
|
|
|
SystemCheck::App::GitlabConfigUpToDateCheck,
|
2017-05-25 10:16:25 -04:00
|
|
|
SystemCheck::App::LogWritableCheck,
|
|
|
|
SystemCheck::App::TmpWritableCheck,
|
|
|
|
SystemCheck::App::UploadsDirectoryExistsCheck,
|
|
|
|
SystemCheck::App::UploadsPathPermissionCheck,
|
|
|
|
SystemCheck::App::UploadsPathTmpPermissionCheck,
|
|
|
|
SystemCheck::App::InitScriptExistsCheck,
|
|
|
|
SystemCheck::App::InitScriptUpToDateCheck,
|
|
|
|
SystemCheck::App::ProjectsHaveNamespaceCheck,
|
|
|
|
SystemCheck::App::RedisVersionCheck,
|
|
|
|
SystemCheck::App::RubyVersionCheck,
|
2017-05-25 19:46:30 -04:00
|
|
|
SystemCheck::App::GitVersionCheck,
|
|
|
|
SystemCheck::App::ActiveUsersCheck
|
2017-05-25 10:16:25 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
SystemCheck.run('GitLab', checks)
|
2013-04-20 08:56:13 -04:00
|
|
|
end
|
2012-12-10 08:50:55 -05:00
|
|
|
end
|
|
|
|
|
2013-02-11 12:16:59 -05:00
|
|
|
namespace :gitlab_shell do
|
2017-05-25 10:16:25 -04:00
|
|
|
include SystemCheck::Helpers
|
|
|
|
|
2015-06-23 10:52:40 -04:00
|
|
|
desc "GitLab | Check the configuration of GitLab Shell"
|
2012-12-10 08:50:55 -05:00
|
|
|
task check: :environment do
|
2012-12-13 06:11:41 -05:00
|
|
|
warn_user_is_not_gitlab
|
2013-05-19 05:13:39 -04:00
|
|
|
start_checking "GitLab Shell"
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2013-03-12 06:53:07 -04:00
|
|
|
check_gitlab_shell
|
2012-12-13 06:11:41 -05:00
|
|
|
check_repo_base_exists
|
2013-01-07 13:39:15 -05:00
|
|
|
check_repo_base_is_not_symlink
|
2012-12-13 06:11:41 -05:00
|
|
|
check_repo_base_user_and_group
|
|
|
|
check_repo_base_permissions
|
2014-09-16 11:11:25 -04:00
|
|
|
check_repos_hooks_directory_is_link
|
2013-09-24 08:36:57 -04:00
|
|
|
check_gitlab_shell_self_test
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2013-05-19 05:13:39 -04:00
|
|
|
finished_checking "GitLab Shell"
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Checks
|
|
|
|
########################
|
|
|
|
|
|
|
|
def check_repo_base_exists
|
2016-06-22 17:04:51 -04:00
|
|
|
puts "Repo base directory exists?"
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2017-02-28 16:08:40 -05:00
|
|
|
Gitlab.config.repositories.storages.each do |name, repository_storage|
|
|
|
|
repo_base_path = repository_storage['path']
|
2016-06-22 17:04:51 -04:00
|
|
|
print "#{name}... "
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2016-08-09 17:23:25 -04:00
|
|
|
if File.exist?(repo_base_path)
|
2016-06-22 17:04:51 -04:00
|
|
|
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
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-07 13:39:15 -05:00
|
|
|
def check_repo_base_is_not_symlink
|
2016-06-22 17:04:51 -04:00
|
|
|
puts "Repo storage directories are symlinks?"
|
2013-01-07 13:39:15 -05:00
|
|
|
|
2017-02-28 16:08:40 -05:00
|
|
|
Gitlab.config.repositories.storages.each do |name, repository_storage|
|
|
|
|
repo_base_path = repository_storage['path']
|
2016-06-22 17:04:51 -04:00
|
|
|
print "#{name}... "
|
2013-01-07 13:39:15 -05:00
|
|
|
|
2016-08-09 17:23:25 -04:00
|
|
|
unless File.exist?(repo_base_path)
|
2016-06-22 17:04:51 -04:00
|
|
|
puts "can't check because of previous errors".color(:magenta)
|
2017-02-22 13:18:40 -05:00
|
|
|
break
|
2016-06-22 17:04:51 -04:00
|
|
|
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
|
2013-01-07 13:39:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
def check_repo_base_permissions
|
2016-06-22 17:04:51 -04:00
|
|
|
puts "Repo paths access is drwxrws---?"
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2017-02-28 16:08:40 -05:00
|
|
|
Gitlab.config.repositories.storages.each do |name, repository_storage|
|
|
|
|
repo_base_path = repository_storage['path']
|
2016-06-22 17:04:51 -04:00
|
|
|
print "#{name}... "
|
2012-04-03 18:02:54 -04:00
|
|
|
|
2016-08-09 17:23:25 -04:00
|
|
|
unless File.exist?(repo_base_path)
|
2016-06-22 17:04:51 -04:00
|
|
|
puts "can't check because of previous errors".color(:magenta)
|
2017-02-22 13:18:40 -05:00
|
|
|
break
|
2016-06-22 17:04:51 -04:00
|
|
|
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
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_repo_base_user_and_group
|
2013-02-11 12:16:59 -05:00
|
|
|
gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user
|
2017-04-12 03:35:48 -04:00
|
|
|
puts "Repo paths owned by #{gitlab_shell_ssh_user}:root, or #{gitlab_shell_ssh_user}:#{Gitlab.config.gitlab_shell.owner_group}?"
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2017-02-28 16:08:40 -05:00
|
|
|
Gitlab.config.repositories.storages.each do |name, repository_storage|
|
|
|
|
repo_base_path = repository_storage['path']
|
2016-06-22 17:04:51 -04:00
|
|
|
print "#{name}... "
|
2012-11-07 18:47:11 -05:00
|
|
|
|
2016-08-09 17:23:25 -04:00
|
|
|
unless File.exist?(repo_base_path)
|
2016-06-22 17:04:51 -04:00
|
|
|
puts "can't check because of previous errors".color(:magenta)
|
2017-02-22 13:18:40 -05:00
|
|
|
break
|
2016-06-22 17:04:51 -04:00
|
|
|
end
|
|
|
|
|
2017-04-12 03:35:48 -04:00
|
|
|
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)
|
2016-06-22 17:04:51 -04:00
|
|
|
puts "yes".color(:green)
|
|
|
|
else
|
|
|
|
puts "no".color(:red)
|
2017-04-12 03:35:48 -04:00
|
|
|
puts " User id for #{gitlab_shell_ssh_user}: #{user_id}. Groupd id for root: #{root_group_id}".color(:blue)
|
2016-06-22 17:04:51 -04:00
|
|
|
try_fixing_it(
|
2017-04-12 03:35:48 -04:00
|
|
|
"sudo chown -R #{gitlab_shell_ssh_user}:root #{repo_base_path}"
|
2016-06-22 17:04:51 -04:00
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section "GitLab Shell"
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-16 11:11:25 -04:00
|
|
|
def check_repos_hooks_directory_is_link
|
|
|
|
print "hooks directories in repos are links: ... "
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2013-02-12 12:42:36 -05:00
|
|
|
gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path
|
2012-08-21 15:44:49 -04:00
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
unless Project.count > 0
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "can't check, you have no projects".color(:magenta)
|
2012-12-13 06:11:41 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
puts ""
|
2012-07-26 09:14:34 -04:00
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
Project.find_each(batch_size: 100) do |project|
|
2014-07-07 08:19:32 -04:00
|
|
|
print sanitized_message(project)
|
2014-09-16 11:11:25 -04:00
|
|
|
project_hook_directory = File.join(project.repository.path_to_repo, "hooks")
|
2012-07-26 09:14:34 -04:00
|
|
|
|
2013-02-01 15:18:09 -05:00
|
|
|
if project.empty_repo?
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "repository is empty".color(:magenta)
|
2015-07-29 12:03:15 -04:00
|
|
|
elsif File.directory?(project_hook_directory) && File.directory?(gitlab_shell_hooks_path) &&
|
|
|
|
(File.realpath(project_hook_directory) == File.realpath(gitlab_shell_hooks_path))
|
2016-06-01 18:37:15 -04:00
|
|
|
puts 'ok'.color(:green)
|
2012-12-13 06:11:41 -05:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "wrong or missing hooks".color(:red)
|
2014-09-16 11:11:25 -04:00
|
|
|
try_fixing_it(
|
2016-06-22 17:04:51 -04:00
|
|
|
sudo_gitlab("#{File.join(gitlab_shell_path, 'bin/create-hooks')} #{repository_storage_paths_args.join(' ')}"),
|
2014-09-16 11:11:25 -04:00
|
|
|
'Check the hooks_path in config/gitlab.yml',
|
|
|
|
'Check your gitlab-shell installation'
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section "GitLab Shell"
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
2012-07-26 09:14:34 -04:00
|
|
|
end
|
|
|
|
end
|
2012-12-10 08:50:55 -05:00
|
|
|
end
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2013-09-24 08:36:57 -04:00
|
|
|
def check_gitlab_shell_self_test
|
2014-03-07 21:05:56 -05:00
|
|
|
gitlab_shell_repo_base = gitlab_shell_path
|
2013-09-24 08:36:57 -04:00
|
|
|
check_cmd = File.expand_path('bin/check', gitlab_shell_repo_base)
|
|
|
|
puts "Running #{check_cmd}"
|
|
|
|
if system(check_cmd, chdir: gitlab_shell_repo_base)
|
2016-06-01 18:37:15 -04:00
|
|
|
puts 'gitlab-shell self-check successful'.color(:green)
|
2013-09-24 08:36:57 -04:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts 'gitlab-shell self-check failed'.color(:red)
|
2013-09-24 08:36:57 -04:00
|
|
|
try_fixing_it(
|
|
|
|
'Make sure GitLab is running;',
|
|
|
|
'Check the gitlab-shell configuration file:',
|
|
|
|
sudo_gitlab("editor #{File.expand_path('config.yml', gitlab_shell_repo_base)}")
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
# Helper methods
|
|
|
|
########################
|
|
|
|
|
2014-03-07 21:05:56 -05:00
|
|
|
def gitlab_shell_path
|
|
|
|
Gitlab.config.gitlab_shell.path
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
|
2013-02-11 12:16:59 -05:00
|
|
|
def gitlab_shell_version
|
2013-11-20 06:41:41 -05:00
|
|
|
Gitlab::Shell.new.version
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
|
2014-06-10 04:23:23 -04:00
|
|
|
def gitlab_shell_major_version
|
2014-11-05 11:14:22 -05:00
|
|
|
Gitlab::Shell.version_required.split('.')[0].to_i
|
2014-06-10 04:23:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_shell_minor_version
|
2014-11-05 11:14:22 -05:00
|
|
|
Gitlab::Shell.version_required.split('.')[1].to_i
|
2014-06-10 04:23:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_shell_patch_version
|
2014-11-05 11:14:22 -05:00
|
|
|
Gitlab::Shell.version_required.split('.')[2].to_i
|
2014-06-10 04:23:23 -04:00
|
|
|
end
|
2012-12-10 08:50:55 -05:00
|
|
|
end
|
2012-07-26 09:14:34 -04:00
|
|
|
|
2013-01-09 18:08:15 -05:00
|
|
|
namespace :sidekiq do
|
2017-05-25 10:16:25 -04:00
|
|
|
include SystemCheck::Helpers
|
|
|
|
|
2015-06-23 10:52:40 -04:00
|
|
|
desc "GitLab | Check the configuration of Sidekiq"
|
2012-12-10 08:50:55 -05:00
|
|
|
task check: :environment do
|
2012-12-13 06:11:41 -05:00
|
|
|
warn_user_is_not_gitlab
|
2013-01-09 18:08:15 -05:00
|
|
|
start_checking "Sidekiq"
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2013-01-09 18:08:15 -05:00
|
|
|
check_sidekiq_running
|
2013-09-27 06:57:05 -04:00
|
|
|
only_one_sidekiq_running
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2013-01-09 18:08:15 -05:00
|
|
|
finished_checking "Sidekiq"
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Checks
|
|
|
|
########################
|
|
|
|
|
2013-01-09 18:08:15 -05:00
|
|
|
def check_sidekiq_running
|
2012-12-13 06:11:41 -05:00
|
|
|
print "Running? ... "
|
|
|
|
|
2013-10-17 05:58:03 -04:00
|
|
|
if sidekiq_process_count > 0
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "yes".color(:green)
|
2012-12-13 06:11:41 -05:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "no".color(:red)
|
2012-12-13 06:11:41 -05:00
|
|
|
try_fixing_it(
|
2014-05-27 11:14:41 -04:00
|
|
|
sudo_gitlab("RAILS_ENV=production bin/background_jobs start")
|
2012-12-13 06:11:41 -05:00
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section("Install Init Script"),
|
2013-01-09 01:14:05 -05:00
|
|
|
"see log/sidekiq.log for possible errors"
|
2012-12-13 06:11:41 -05:00
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
2013-09-27 06:57:05 -04:00
|
|
|
|
|
|
|
def only_one_sidekiq_running
|
2013-10-17 05:58:03 -04:00
|
|
|
process_count = sidekiq_process_count
|
|
|
|
return if process_count.zero?
|
2013-09-27 06:57:05 -04:00
|
|
|
|
|
|
|
print 'Number of Sidekiq processes ... '
|
2013-10-17 05:58:03 -04:00
|
|
|
if process_count == 1
|
2016-06-01 18:37:15 -04:00
|
|
|
puts '1'.color(:green)
|
2013-09-27 06:57:05 -04:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "#{process_count}".color(:red)
|
2013-09-27 06:57:05 -04:00
|
|
|
try_fixing_it(
|
|
|
|
'sudo service gitlab stop',
|
2013-10-04 05:18:44 -04:00
|
|
|
"sudo pkill -u #{gitlab_user} -f sidekiq",
|
|
|
|
"sleep 10 && sudo pkill -9 -u #{gitlab_user} -f sidekiq",
|
2013-09-27 06:57:05 -04:00
|
|
|
'sudo service gitlab start'
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-17 05:58:03 -04:00
|
|
|
def sidekiq_process_count
|
2017-03-26 02:58:49 -04:00
|
|
|
ps_ux, _ = Gitlab::Popen.popen(%w(ps uxww))
|
2014-02-25 06:12:09 -05:00
|
|
|
ps_ux.scan(/sidekiq \d+\.\d+\.\d+/).count
|
2013-09-27 06:57:05 -04:00
|
|
|
end
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
|
2015-09-21 03:46:47 -04:00
|
|
|
namespace :incoming_email do
|
2017-05-25 10:16:25 -04:00
|
|
|
include SystemCheck::Helpers
|
|
|
|
|
2015-08-20 17:03:04 -04:00
|
|
|
desc "GitLab | Check the configuration of Reply by email"
|
|
|
|
task check: :environment do
|
|
|
|
warn_user_is_not_gitlab
|
|
|
|
start_checking "Reply by email"
|
|
|
|
|
2015-09-21 03:46:47 -04:00
|
|
|
if Gitlab.config.incoming_email.enabled
|
2015-08-20 17:03:04 -04:00
|
|
|
check_imap_authentication
|
2015-08-21 18:06:04 -04:00
|
|
|
|
2015-08-21 18:03:16 -04:00
|
|
|
if Rails.env.production?
|
|
|
|
check_initd_configured_correctly
|
|
|
|
check_mail_room_running
|
|
|
|
else
|
|
|
|
check_foreman_configured_correctly
|
|
|
|
end
|
2015-08-20 17:03:04 -04:00
|
|
|
else
|
|
|
|
puts 'Reply by email is disabled in config/gitlab.yml'
|
|
|
|
end
|
|
|
|
|
|
|
|
finished_checking "Reply by email"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Checks
|
|
|
|
########################
|
|
|
|
|
|
|
|
def check_initd_configured_correctly
|
2017-06-09 11:17:49 -04:00
|
|
|
return if omnibus_gitlab?
|
2015-08-20 17:03:04 -04:00
|
|
|
|
2017-06-09 11:17:49 -04:00
|
|
|
print "Init.d configured correctly? ... "
|
2015-09-22 15:56:49 -04:00
|
|
|
|
2015-08-20 17:03:04 -04:00
|
|
|
path = "/etc/default/gitlab"
|
|
|
|
|
|
|
|
if File.exist?(path) && File.read(path).include?("mail_room_enabled=true")
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "yes".color(:green)
|
2015-08-20 17:03:04 -04:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "no".color(:red)
|
2015-08-20 17:03:04 -04:00
|
|
|
try_fixing_it(
|
|
|
|
"Enable mail_room in the init.d configuration."
|
|
|
|
)
|
|
|
|
for_more_information(
|
2016-09-25 05:55:14 -04:00
|
|
|
"doc/administration/reply_by_email.md"
|
2015-08-20 17:03:04 -04:00
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-21 18:03:16 -04:00
|
|
|
def check_foreman_configured_correctly
|
|
|
|
print "Foreman configured correctly? ... "
|
|
|
|
|
|
|
|
path = Rails.root.join("Procfile")
|
|
|
|
|
2015-08-21 18:06:04 -04:00
|
|
|
if File.exist?(path) && File.read(path) =~ /^mail_room:/
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "yes".color(:green)
|
2015-08-21 18:03:16 -04:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "no".color(:red)
|
2015-08-21 18:03:16 -04:00
|
|
|
try_fixing_it(
|
|
|
|
"Enable mail_room in your Procfile."
|
|
|
|
)
|
|
|
|
for_more_information(
|
2016-09-25 05:55:14 -04:00
|
|
|
"doc/administration/reply_by_email.md"
|
2015-08-21 18:03:16 -04:00
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-20 17:03:04 -04:00
|
|
|
def check_mail_room_running
|
2017-06-09 11:17:49 -04:00
|
|
|
return if omnibus_gitlab?
|
|
|
|
|
2015-08-20 17:03:04 -04:00
|
|
|
print "MailRoom running? ... "
|
|
|
|
|
|
|
|
path = "/etc/default/gitlab"
|
|
|
|
|
|
|
|
unless File.exist?(path) && File.read(path).include?("mail_room_enabled=true")
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "can't check because of previous errors".color(:magenta)
|
2015-08-20 17:03:04 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-08-20 17:09:37 -04:00
|
|
|
if mail_room_running?
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "yes".color(:green)
|
2015-08-20 17:03:04 -04:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "no".color(:red)
|
2015-08-20 17:03:04 -04:00
|
|
|
try_fixing_it(
|
|
|
|
sudo_gitlab("RAILS_ENV=production bin/mail_room start")
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section("Install Init Script"),
|
|
|
|
"see log/mail_room.log for possible errors"
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_imap_authentication
|
|
|
|
print "IMAP server credentials are correct? ... "
|
|
|
|
|
2017-02-21 12:50:28 -05:00
|
|
|
config_path = Rails.root.join('config', 'mail_room.yml').to_s
|
|
|
|
erb = ERB.new(File.read(config_path))
|
|
|
|
erb.filename = config_path
|
|
|
|
config_file = YAML.load(erb.result)
|
|
|
|
|
2016-02-29 05:04:40 -05:00
|
|
|
config = config_file[:mailboxes].first
|
2015-08-20 17:03:04 -04:00
|
|
|
|
|
|
|
if config
|
|
|
|
begin
|
2016-02-29 05:04:40 -05:00
|
|
|
imap = Net::IMAP.new(config[:host], port: config[:port], ssl: config[:ssl])
|
|
|
|
imap.starttls if config[:start_tls]
|
|
|
|
imap.login(config[:email], config[:password])
|
2015-08-20 17:03:04 -04:00
|
|
|
connected = true
|
|
|
|
rescue
|
|
|
|
connected = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if connected
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "yes".color(:green)
|
2015-08-20 17:03:04 -04:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "no".color(:red)
|
2015-08-20 17:03:04 -04:00
|
|
|
try_fixing_it(
|
2015-10-13 07:07:59 -04:00
|
|
|
"Check that the information in config/gitlab.yml is correct"
|
2015-08-20 17:03:04 -04:00
|
|
|
)
|
|
|
|
for_more_information(
|
2016-09-25 05:55:14 -04:00
|
|
|
"doc/administration/reply_by_email.md"
|
2015-08-20 17:03:04 -04:00
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-20 17:09:37 -04:00
|
|
|
def mail_room_running?
|
2017-03-26 02:58:49 -04:00
|
|
|
ps_ux, _ = Gitlab::Popen.popen(%w(ps uxww))
|
2015-08-20 17:09:37 -04:00
|
|
|
ps_ux.include?("mail_room")
|
2015-08-20 17:03:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-28 09:20:40 -05:00
|
|
|
namespace :ldap do
|
2017-05-25 10:16:25 -04:00
|
|
|
include SystemCheck::Helpers
|
|
|
|
|
2016-09-29 15:08:27 -04:00
|
|
|
task :check, [:limit] => :environment do |_, args|
|
2014-01-16 12:40:45 -05:00
|
|
|
# Only show up to 100 results because LDAP directories can be very big.
|
|
|
|
# This setting only affects the `rake gitlab:check` script.
|
2013-12-03 12:51:21 -05:00
|
|
|
args.with_defaults(limit: 100)
|
2013-11-28 09:20:40 -05:00
|
|
|
warn_user_is_not_gitlab
|
|
|
|
start_checking "LDAP"
|
|
|
|
|
2014-10-21 11:26:40 -04:00
|
|
|
if Gitlab::LDAP::Config.enabled?
|
2016-09-29 15:08:27 -04:00
|
|
|
check_ldap(args.limit)
|
2013-11-28 12:12:30 -05:00
|
|
|
else
|
|
|
|
puts 'LDAP is disabled in config/gitlab.yml'
|
|
|
|
end
|
2013-11-28 09:20:40 -05:00
|
|
|
|
|
|
|
finished_checking "LDAP"
|
|
|
|
end
|
|
|
|
|
2016-09-29 15:08:27 -04:00
|
|
|
def check_ldap(limit)
|
2014-10-22 04:11:18 -04:00
|
|
|
servers = Gitlab::LDAP::Config.providers
|
2014-03-26 10:38:14 -04:00
|
|
|
|
2014-10-21 11:26:40 -04:00
|
|
|
servers.each do |server|
|
|
|
|
puts "Server: #{server}"
|
2016-09-29 15:08:27 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
Gitlab::LDAP::Adapter.open(server) do |adapter|
|
|
|
|
check_ldap_auth(adapter)
|
|
|
|
|
|
|
|
puts "LDAP users with access to your GitLab server (only showing the first #{limit} results)"
|
|
|
|
|
|
|
|
users = adapter.users(adapter.config.uid, '*', limit)
|
|
|
|
users.each do |user|
|
|
|
|
puts "\tDN: #{user.dn}\t #{adapter.config.uid}: #{user.uid}"
|
|
|
|
end
|
2014-10-21 11:26:40 -04:00
|
|
|
end
|
2016-09-29 15:08:27 -04:00
|
|
|
rescue Net::LDAP::ConnectionRefusedError, Errno::ECONNREFUSED => e
|
|
|
|
puts "Could not connect to the LDAP server: #{e.message}".color(:red)
|
2014-10-21 11:26:40 -04:00
|
|
|
end
|
2014-03-26 10:38:14 -04:00
|
|
|
end
|
2013-11-28 09:20:40 -05:00
|
|
|
end
|
2016-09-29 15:08:27 -04:00
|
|
|
|
|
|
|
def check_ldap_auth(adapter)
|
|
|
|
auth = adapter.config.has_auth?
|
|
|
|
|
2017-02-22 13:18:40 -05:00
|
|
|
message = if auth && adapter.ldap.bind
|
|
|
|
'Success'.color(:green)
|
|
|
|
elsif auth
|
|
|
|
'Failed. Check `bind_dn` and `password` configuration values'.color(:red)
|
|
|
|
else
|
|
|
|
'Anonymous. No `bind_dn` or `password` configured'.color(:yellow)
|
|
|
|
end
|
2016-09-29 15:08:27 -04:00
|
|
|
|
|
|
|
puts "LDAP authentication... #{message}"
|
|
|
|
end
|
2013-11-28 09:20:40 -05:00
|
|
|
end
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2015-04-16 00:15:56 -04:00
|
|
|
namespace :repo do
|
2017-05-25 10:16:25 -04:00
|
|
|
include SystemCheck::Helpers
|
|
|
|
|
2015-06-23 10:52:40 -04:00
|
|
|
desc "GitLab | Check the integrity of the repositories managed by GitLab"
|
2015-04-16 00:15:56 -04:00
|
|
|
task check: :environment do
|
2017-02-28 16:08:40 -05:00
|
|
|
Gitlab.config.repositories.storages.each do |name, repository_storage|
|
|
|
|
namespace_dirs = Dir.glob(File.join(repository_storage['path'], '*'))
|
2015-04-16 00:15:56 -04:00
|
|
|
|
2016-06-22 17:04:51 -04:00
|
|
|
namespace_dirs.each do |namespace_dir|
|
|
|
|
repo_dirs = Dir.glob(File.join(namespace_dir, '*'))
|
|
|
|
repo_dirs.each { |repo_dir| check_repo_integrity(repo_dir) }
|
|
|
|
end
|
2015-12-11 18:27:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :user do
|
2017-05-25 10:16:25 -04:00
|
|
|
include SystemCheck::Helpers
|
|
|
|
|
2015-12-11 18:27:20 -05:00
|
|
|
desc "GitLab | Check the integrity of a specific user's repositories"
|
|
|
|
task :check_repos, [:username] => :environment do |t, args|
|
2016-06-22 17:04:51 -04:00
|
|
|
username = args[:username] || prompt("Check repository integrity for fsername? ".color(:blue))
|
2015-12-11 18:27:20 -05:00
|
|
|
user = User.find_by(username: username)
|
|
|
|
if user
|
|
|
|
repo_dirs = user.authorized_projects.map do |p|
|
2017-02-22 13:18:40 -05:00
|
|
|
File.join(
|
|
|
|
p.repository_storage_path,
|
|
|
|
"#{p.path_with_namespace}.git"
|
|
|
|
)
|
|
|
|
end
|
2015-12-11 18:27:20 -05:00
|
|
|
|
|
|
|
repo_dirs.each { |repo_dir| check_repo_integrity(repo_dir) }
|
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "\nUser '#{username}' not found".color(:red)
|
2015-04-16 00:15:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
# Helper methods
|
|
|
|
##########################
|
|
|
|
|
2013-03-12 06:53:07 -04:00
|
|
|
def check_gitlab_shell
|
2014-06-10 04:23:23 -04:00
|
|
|
required_version = Gitlab::VersionInfo.new(gitlab_shell_major_version, gitlab_shell_minor_version, gitlab_shell_patch_version)
|
2013-05-08 01:19:51 -04:00
|
|
|
current_version = Gitlab::VersionInfo.parse(gitlab_shell_version)
|
2013-04-30 07:49:35 -04:00
|
|
|
|
2013-05-08 01:19:51 -04:00
|
|
|
print "GitLab Shell version >= #{required_version} ? ... "
|
2013-06-05 21:10:51 -04:00
|
|
|
if current_version.valid? && required_version <= current_version
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "OK (#{current_version})".color(:green)
|
2013-03-12 06:53:07 -04:00
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "FAIL. Please update gitlab-shell to #{required_version} from #{current_version}".color(:red)
|
2013-03-12 06:53:07 -04:00
|
|
|
end
|
|
|
|
end
|
2013-05-06 08:08:53 -04:00
|
|
|
|
2015-12-11 18:27:20 -05:00
|
|
|
def check_repo_integrity(repo_dir)
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "\nChecking repo at #{repo_dir.color(:yellow)}"
|
2015-12-11 18:27:20 -05:00
|
|
|
|
|
|
|
git_fsck(repo_dir)
|
|
|
|
check_config_lock(repo_dir)
|
|
|
|
check_ref_locks(repo_dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
def git_fsck(repo_dir)
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "Running `git fsck`".color(:yellow)
|
2015-12-11 18:27:20 -05:00
|
|
|
system(*%W(#{Gitlab.config.git.bin_path} fsck), chdir: repo_dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_config_lock(repo_dir)
|
2017-02-22 13:18:40 -05:00
|
|
|
config_exists = File.exist?(File.join(repo_dir, 'config.lock'))
|
2016-06-01 18:37:15 -04:00
|
|
|
config_output = config_exists ? 'yes'.color(:red) : 'no'.color(:green)
|
|
|
|
puts "'config.lock' file exists?".color(:yellow) + " ... #{config_output}"
|
2015-12-11 18:27:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_ref_locks(repo_dir)
|
2017-02-22 13:18:40 -05:00
|
|
|
lock_files = Dir.glob(File.join(repo_dir, 'refs/heads/*.lock'))
|
2015-12-11 18:27:20 -05:00
|
|
|
if lock_files.present?
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "Ref lock files exist:".color(:red)
|
2015-12-11 18:27:20 -05:00
|
|
|
lock_files.each do |lock_file|
|
|
|
|
puts " #{lock_file}"
|
|
|
|
end
|
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "No ref lock files exist".color(:green)
|
2015-12-11 18:27:20 -05:00
|
|
|
end
|
|
|
|
end
|
2012-04-03 18:02:54 -04:00
|
|
|
end
|