2012-04-03 18:02:54 -04:00
|
|
|
namespace :gitlab do
|
2012-12-10 08:50:55 -05:00
|
|
|
desc "GITLAB | Check the configuration of GitLab and its environment"
|
|
|
|
task check: %w{gitlab:env:check
|
2013-02-11 12:16:59 -05:00
|
|
|
gitlab:gitlab_shell:check
|
2013-01-09 18:08:15 -05:00
|
|
|
gitlab:sidekiq:check
|
2013-11-28 09:20:40 -05:00
|
|
|
gitlab:ldap:check
|
2012-12-13 06:11:41 -05:00
|
|
|
gitlab:app:check}
|
|
|
|
|
|
|
|
|
2012-12-10 08:50:55 -05:00
|
|
|
|
2012-04-03 18:02:54 -04:00
|
|
|
namespace :app do
|
2012-12-10 08:50:55 -05:00
|
|
|
desc "GITLAB | Check the configuration of the GitLab Rails app"
|
|
|
|
task check: :environment do
|
2012-12-13 06:11:41 -05:00
|
|
|
warn_user_is_not_gitlab
|
|
|
|
start_checking "GitLab"
|
|
|
|
|
|
|
|
check_database_config_exists
|
|
|
|
check_database_is_not_sqlite
|
|
|
|
check_migrations_are_up
|
2014-09-14 12:51:54 -04:00
|
|
|
check_orphaned_group_members
|
2012-12-13 06:11:41 -05:00
|
|
|
check_gitlab_config_exists
|
|
|
|
check_gitlab_config_not_outdated
|
|
|
|
check_log_writable
|
|
|
|
check_tmp_writable
|
|
|
|
check_init_script_exists
|
|
|
|
check_init_script_up_to_date
|
2013-09-24 02:31:12 -04:00
|
|
|
check_projects_have_namespace
|
2012-12-13 06:11:41 -05:00
|
|
|
check_satellites_exist
|
2013-04-14 16:17:06 -04:00
|
|
|
check_redis_version
|
2014-07-23 04:44:27 -04:00
|
|
|
check_ruby_version
|
2013-05-06 08:08:53 -04:00
|
|
|
check_git_version
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
finished_checking "GitLab"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Checks
|
|
|
|
########################
|
|
|
|
|
|
|
|
def check_database_config_exists
|
|
|
|
print "Database config exists? ... "
|
|
|
|
|
|
|
|
database_config_file = Rails.root.join("config", "database.yml")
|
|
|
|
|
|
|
|
if File.exists?(database_config_file)
|
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
|
|
|
"Copy config/database.yml.<your db> to config/database.yml",
|
|
|
|
"Check that the information in config/database.yml is correct"
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_database_guide,
|
|
|
|
"http://guides.rubyonrails.org/getting_started.html#configuring-a-database"
|
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_database_is_not_sqlite
|
2012-12-23 14:47:55 -05:00
|
|
|
print "Database is SQLite ... "
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
database_config_file = Rails.root.join("config", "database.yml")
|
|
|
|
|
2012-12-24 09:52:49 -05:00
|
|
|
unless File.read(database_config_file) =~ /adapter:\s+sqlite/
|
2012-12-23 14:47:55 -05:00
|
|
|
puts "no".green
|
2012-12-13 06:11:41 -05:00
|
|
|
else
|
2012-12-23 14:47:55 -05:00
|
|
|
puts "yes".red
|
2014-01-06 13:36:34 -05:00
|
|
|
puts "Please fix this by removing the SQLite entry from the database.yml".blue
|
2012-12-13 06:11:41 -05:00
|
|
|
for_more_information(
|
|
|
|
"https://github.com/gitlabhq/gitlabhq/wiki/Migrate-from-SQLite-to-MySQL",
|
|
|
|
see_database_guide
|
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_gitlab_config_exists
|
|
|
|
print "GitLab config exists? ... "
|
|
|
|
|
|
|
|
gitlab_config_file = Rails.root.join("config", "gitlab.yml")
|
|
|
|
|
|
|
|
if File.exists?(gitlab_config_file)
|
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
|
|
|
"Copy config/gitlab.yml.example to config/gitlab.yml",
|
|
|
|
"Update config/gitlab.yml to match your setup"
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section "GitLab"
|
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_gitlab_config_not_outdated
|
2012-12-20 10:51:14 -05:00
|
|
|
print "GitLab config outdated? ... "
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
gitlab_config_file = Rails.root.join("config", "gitlab.yml")
|
|
|
|
unless File.exists?(gitlab_config_file)
|
|
|
|
puts "can't check because of previous errors".magenta
|
|
|
|
end
|
|
|
|
|
|
|
|
# omniauth or ldap could have been deleted from the file
|
2013-01-07 13:47:53 -05:00
|
|
|
unless Gitlab.config['git_host']
|
2012-12-20 10:51:14 -05:00
|
|
|
puts "no".green
|
2012-12-13 06:11:41 -05:00
|
|
|
else
|
2012-12-20 10:51:14 -05:00
|
|
|
puts "yes".red
|
2012-12-13 06:11:41 -05:00
|
|
|
try_fixing_it(
|
2012-12-20 10:51:14 -05:00
|
|
|
"Backup your config/gitlab.yml",
|
2012-12-13 06:11:41 -05:00
|
|
|
"Copy config/gitlab.yml.example to config/gitlab.yml",
|
|
|
|
"Update config/gitlab.yml to match your setup"
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section "GitLab"
|
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
2012-04-03 18:02:54 -04:00
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
def check_init_script_exists
|
|
|
|
print "Init script exists? ... "
|
|
|
|
|
2014-06-12 03:28:34 -04:00
|
|
|
if omnibus_gitlab?
|
|
|
|
puts 'skipped (omnibus-gitlab has no init script)'.magenta
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
script_path = "/etc/init.d/gitlab"
|
|
|
|
|
|
|
|
if File.exists?(script_path)
|
|
|
|
puts "yes".green
|
2012-09-26 07:18:10 -04:00
|
|
|
else
|
2012-12-13 06:11:41 -05:00
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
|
|
|
"Install the init script"
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section "Install Init Script"
|
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_init_script_up_to_date
|
|
|
|
print "Init script up-to-date? ... "
|
|
|
|
|
2014-06-12 03:28:34 -04:00
|
|
|
if omnibus_gitlab?
|
|
|
|
puts 'skipped (omnibus-gitlab has no init script)'.magenta
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-04 18:11:43 -04:00
|
|
|
recipe_path = Rails.root.join("lib/support/init.d/", "gitlab")
|
2012-12-13 06:11:41 -05:00
|
|
|
script_path = "/etc/init.d/gitlab"
|
2013-06-04 18:11:43 -04:00
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
unless File.exists?(script_path)
|
|
|
|
puts "can't check because of previous errors".magenta
|
2012-04-03 18:02:54 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-04 18:11:43 -04:00
|
|
|
recipe_content = File.read(recipe_path)
|
2012-12-13 06:11:41 -05:00
|
|
|
script_content = File.read(script_path)
|
|
|
|
|
|
|
|
if recipe_content == script_content
|
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
|
|
|
"Redownload the init script"
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section "Install Init Script"
|
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_migrations_are_up
|
|
|
|
print "All migrations up? ... "
|
|
|
|
|
2014-02-25 06:12:09 -05:00
|
|
|
migration_status, _ = Gitlab::Popen.popen(%W(bundle exec rake db:migrate:status))
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
unless migration_status =~ /down\s+\d{14}/
|
|
|
|
puts "yes".green
|
2012-04-03 18:02:54 -04:00
|
|
|
else
|
2012-12-13 06:11:41 -05:00
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
2013-01-26 09:22:48 -05:00
|
|
|
sudo_gitlab("bundle exec rake db:migrate RAILS_ENV=production")
|
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
|
|
|
|
|
2014-09-14 12:51:54 -04:00
|
|
|
def check_orphaned_group_members
|
2014-09-14 12:32:51 -04:00
|
|
|
print "Database contains orphaned GroupMembers? ... "
|
|
|
|
if GroupMember.where("user_id not in (select id from users)").count > 0
|
2014-03-14 12:25:11 -04:00
|
|
|
puts "yes".red
|
2014-03-17 06:16:55 -04:00
|
|
|
try_fixing_it(
|
|
|
|
"You can delete the orphaned records using something along the lines of:",
|
2014-09-14 12:32:51 -04:00
|
|
|
sudo_gitlab("bundle exec rails runner -e production 'GroupMember.where(\"user_id NOT IN (SELECT id FROM users)\").delete_all'")
|
2014-03-17 06:16:55 -04:00
|
|
|
)
|
2014-03-14 12:25:11 -04:00
|
|
|
else
|
|
|
|
puts "no".green
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
def check_satellites_exist
|
|
|
|
print "Projects have satellites? ... "
|
|
|
|
|
|
|
|
unless Project.count > 0
|
|
|
|
puts "can't check, you have no projects".magenta
|
2012-04-03 18:02:54 -04:00
|
|
|
return
|
|
|
|
end
|
2012-12-13 06:11:41 -05:00
|
|
|
puts ""
|
|
|
|
|
|
|
|
Project.find_each(batch_size: 100) do |project|
|
2014-07-07 08:19:32 -04:00
|
|
|
print sanitized_message(project)
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
if project.satellite.exists?
|
|
|
|
puts "yes".green
|
2012-12-23 14:47:31 -05:00
|
|
|
elsif project.empty_repo?
|
|
|
|
puts "can't create, repository is empty".magenta
|
2012-12-13 06:11:41 -05:00
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
2013-01-26 09:22:48 -05:00
|
|
|
sudo_gitlab("bundle exec rake gitlab:satellites:create RAILS_ENV=production"),
|
2012-12-20 15:52:26 -05:00
|
|
|
"If necessary, remove the tmp/repo_satellites directory ...",
|
|
|
|
"... and rerun the above command"
|
2012-12-13 06:11:41 -05:00
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
"doc/raketasks/maintenance.md "
|
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_log_writable
|
|
|
|
print "Log directory writable? ... "
|
|
|
|
|
|
|
|
log_path = Rails.root.join("log")
|
|
|
|
|
|
|
|
if File.writable?(log_path)
|
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
|
|
|
"sudo chown -R gitlab #{log_path}",
|
2013-05-27 15:30:54 -04:00
|
|
|
"sudo chmod -R u+rwX #{log_path}"
|
2012-12-13 06:11:41 -05:00
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section "GitLab"
|
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_tmp_writable
|
|
|
|
print "Tmp directory writable? ... "
|
|
|
|
|
|
|
|
tmp_path = Rails.root.join("tmp")
|
|
|
|
|
|
|
|
if File.writable?(tmp_path)
|
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
|
|
|
"sudo chown -R gitlab #{tmp_path}",
|
2013-05-27 15:30:54 -04:00
|
|
|
"sudo chmod -R u+rwX #{tmp_path}"
|
2012-12-13 06:11:41 -05:00
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section "GitLab"
|
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
2012-12-10 08:50:55 -05:00
|
|
|
end
|
2013-04-20 08:56:13 -04:00
|
|
|
|
2013-04-14 16:17:06 -04:00
|
|
|
def check_redis_version
|
2013-04-20 08:56:13 -04:00
|
|
|
print "Redis version >= 2.0.0? ... "
|
|
|
|
|
2014-03-07 21:35:45 -05:00
|
|
|
if run_and_match(%W(redis-cli --version), /redis-cli 2.\d.\d/)
|
2013-04-14 16:17:06 -04:00
|
|
|
puts "yes".green
|
2013-04-20 08:56:13 -04:00
|
|
|
else
|
2013-04-14 16:17:06 -04:00
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
2013-04-20 08:56:13 -04:00
|
|
|
"Update your redis server to a version >= 2.0.0"
|
2013-04-14 16:17:06 -04:00
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
"gitlab-public-wiki/wiki/Trouble-Shooting-Guide in section sidekiq"
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
2013-04-20 08:56:13 -04:00
|
|
|
end
|
2012-12-10 08:50:55 -05:00
|
|
|
end
|
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
|
2012-12-10 08:50:55 -05:00
|
|
|
namespace :env do
|
|
|
|
desc "GITLAB | Check the configuration of the environment"
|
|
|
|
task check: :environment do
|
2012-12-13 06:11:41 -05:00
|
|
|
warn_user_is_not_gitlab
|
|
|
|
start_checking "Environment"
|
|
|
|
|
|
|
|
check_gitlab_git_config
|
|
|
|
|
|
|
|
finished_checking "Environment"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Checks
|
|
|
|
########################
|
|
|
|
|
|
|
|
def check_gitlab_git_config
|
2013-01-16 18:09:08 -05:00
|
|
|
print "Git configured for #{gitlab_user} user? ... "
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
options = {
|
|
|
|
"user.name" => "GitLab",
|
2014-08-04 23:41:20 -04:00
|
|
|
"user.email" => Gitlab.config.gitlab.email_from,
|
|
|
|
"core.autocrlf" => "input"
|
2012-12-13 06:11:41 -05:00
|
|
|
}
|
|
|
|
correct_options = options.map do |name, value|
|
2014-08-14 01:55:41 -04:00
|
|
|
run(%W(#{Gitlab.config.git.bin_path} config --global --get #{name})).try(:squish) == value
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if correct_options.all?
|
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
2014-08-14 01:55:41 -04:00
|
|
|
sudo_gitlab("\"#{Gitlab.config.git.bin_path}\" config --global user.name \"#{options["user.name"]}\""),
|
|
|
|
sudo_gitlab("\"#{Gitlab.config.git.bin_path}\" config --global user.email \"#{options["user.email"]}\""),
|
|
|
|
sudo_gitlab("\"#{Gitlab.config.git.bin_path}\" config --global core.autocrlf \"#{options["core.autocrlf"]}\"")
|
2012-12-13 06:11:41 -05:00
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section "GitLab"
|
|
|
|
)
|
2012-12-22 19:33:58 -05:00
|
|
|
fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
2012-12-10 08:50:55 -05:00
|
|
|
end
|
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
|
2013-02-11 12:16:59 -05:00
|
|
|
namespace :gitlab_shell do
|
2013-05-19 05:13:39 -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-04-02 09:25:26 -04:00
|
|
|
check_satellites_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
|
|
|
|
print "Repo base directory exists? ... "
|
|
|
|
|
2013-02-11 12:16:59 -05:00
|
|
|
repo_base_path = Gitlab.config.gitlab_shell.repos_path
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
if File.exists?(repo_base_path)
|
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
puts "#{repo_base_path} is missing".red
|
|
|
|
try_fixing_it(
|
2013-05-19 05:13:39 -04:00
|
|
|
"This should have been created when setting up GitLab Shell.",
|
2012-12-13 06:11:41 -05:00
|
|
|
"Make sure it's set correctly in config/gitlab.yml",
|
2013-05-19 05:13:39 -04:00
|
|
|
"Make sure GitLab Shell is installed correctly."
|
2012-12-13 06:11:41 -05:00
|
|
|
)
|
|
|
|
for_more_information(
|
2013-05-19 05:13:39 -04:00
|
|
|
see_installation_guide_section "GitLab Shell"
|
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-01-07 13:39:15 -05:00
|
|
|
def check_repo_base_is_not_symlink
|
|
|
|
print "Repo base directory is a symlink? ... "
|
|
|
|
|
2013-02-11 12:16:59 -05:00
|
|
|
repo_base_path = Gitlab.config.gitlab_shell.repos_path
|
2013-01-07 13:39:15 -05:00
|
|
|
unless File.exists?(repo_base_path)
|
|
|
|
puts "can't check because of previous errors".magenta
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
unless File.symlink?(repo_base_path)
|
|
|
|
puts "no".green
|
|
|
|
else
|
|
|
|
puts "yes".red
|
|
|
|
try_fixing_it(
|
|
|
|
"Make sure it's set to the real directory in config/gitlab.yml"
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
def check_repo_base_permissions
|
2012-12-30 21:46:28 -05:00
|
|
|
print "Repo base access is drwxrws---? ... "
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2013-02-11 12:16:59 -05:00
|
|
|
repo_base_path = Gitlab.config.gitlab_shell.repos_path
|
2012-12-13 06:11:41 -05:00
|
|
|
unless File.exists?(repo_base_path)
|
|
|
|
puts "can't check because of previous errors".magenta
|
2012-04-03 18:02:54 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-02-01 14:56:03 -05:00
|
|
|
if File.stat(repo_base_path).mode.to_s(8).ends_with?("2770")
|
2012-12-13 06:11:41 -05:00
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
2012-12-30 21:46:28 -05:00
|
|
|
"sudo chmod -R ug+rwX,o-rwx #{repo_base_path}",
|
2013-02-01 15:06:15 -05:00
|
|
|
"sudo chmod -R ug-s #{repo_base_path}",
|
2013-01-18 14:13:38 -05:00
|
|
|
"find #{repo_base_path} -type d -print0 | sudo xargs -0 chmod g+s"
|
2012-12-13 06:11:41 -05:00
|
|
|
)
|
|
|
|
for_more_information(
|
2013-05-19 05:13:39 -04:00
|
|
|
see_installation_guide_section "GitLab Shell"
|
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
|
|
|
|
|
2014-04-02 09:25:26 -04:00
|
|
|
def check_satellites_permissions
|
|
|
|
print "Satellites access is drwxr-x---? ... "
|
|
|
|
|
|
|
|
satellites_path = Gitlab.config.satellites.path
|
|
|
|
unless File.exists?(satellites_path)
|
|
|
|
puts "can't check because of previous errors".magenta
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if File.stat(satellites_path).mode.to_s(8).ends_with?("0750")
|
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
2014-04-27 05:36:45 -04:00
|
|
|
"sudo chmod u+rwx,g=rx,o-rwx #{satellites_path}",
|
2014-04-02 09:25:26 -04:00
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section "GitLab"
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
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
|
|
|
|
gitlab_shell_owner_group = Gitlab.config.gitlab_shell.owner_group
|
|
|
|
print "Repo base owned by #{gitlab_shell_ssh_user}:#{gitlab_shell_owner_group}? ... "
|
2012-12-13 06:11:41 -05:00
|
|
|
|
2013-02-11 12:16:59 -05:00
|
|
|
repo_base_path = Gitlab.config.gitlab_shell.repos_path
|
2012-12-13 06:11:41 -05:00
|
|
|
unless File.exists?(repo_base_path)
|
|
|
|
puts "can't check because of previous errors".magenta
|
2012-11-07 18:47:11 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-09-12 09:28:46 -04:00
|
|
|
uid = uid_for(gitlab_shell_ssh_user)
|
|
|
|
gid = gid_for(gitlab_shell_owner_group)
|
|
|
|
if File.stat(repo_base_path).uid == uid && File.stat(repo_base_path).gid == gid
|
2012-12-13 06:11:41 -05:00
|
|
|
puts "yes".green
|
2012-04-03 18:02:54 -04:00
|
|
|
else
|
2012-12-13 06:11:41 -05:00
|
|
|
puts "no".red
|
2013-09-12 09:28:46 -04:00
|
|
|
puts " User id for #{gitlab_shell_ssh_user}: #{uid}. Groupd id for #{gitlab_shell_owner_group}: #{gid}".blue
|
2012-12-13 06:11:41 -05:00
|
|
|
try_fixing_it(
|
2013-02-11 12:16:59 -05:00
|
|
|
"sudo chown -R #{gitlab_shell_ssh_user}:#{gitlab_shell_owner_group} #{repo_base_path}"
|
2012-12-13 06:11:41 -05:00
|
|
|
)
|
|
|
|
for_more_information(
|
2013-05-19 05:13:39 -04:00
|
|
|
see_installation_guide_section "GitLab Shell"
|
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
|
|
|
|
|
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
|
|
|
|
puts "can't check, you have no projects".magenta
|
|
|
|
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?
|
|
|
|
puts "repository is empty".magenta
|
2014-09-16 11:11:25 -04:00
|
|
|
elsif File.realpath(project_hook_directory) == File.realpath(gitlab_shell_hooks_path)
|
|
|
|
puts 'ok'.green
|
2012-12-13 06:11:41 -05:00
|
|
|
else
|
2014-09-16 11:11:25 -04:00
|
|
|
puts "wrong or missing hooks".red
|
|
|
|
try_fixing_it(
|
|
|
|
sudo_gitlab("#{gitlab_shell_path}/bin/create-hooks"),
|
|
|
|
'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
|
2014-09-16 11:11:25 -04:00
|
|
|
|
2012-07-26 09:14:34 -04:00
|
|
|
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)
|
|
|
|
puts 'gitlab-shell self-check successful'.green
|
|
|
|
else
|
|
|
|
puts 'gitlab-shell self-check failed'.red
|
|
|
|
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
|
|
|
|
|
2013-09-24 02:31:12 -04:00
|
|
|
def check_projects_have_namespace
|
|
|
|
print "projects have namespace: ... "
|
|
|
|
|
|
|
|
unless Project.count > 0
|
|
|
|
puts "can't check, you have no projects".magenta
|
|
|
|
return
|
|
|
|
end
|
|
|
|
puts ""
|
|
|
|
|
|
|
|
Project.find_each(batch_size: 100) do |project|
|
2014-07-07 08:19:32 -04:00
|
|
|
print sanitized_message(project)
|
2013-09-24 02:31:12 -04:00
|
|
|
|
|
|
|
if project.namespace
|
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
|
|
|
"Migrate global projects"
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
"doc/update/5.4-to-6.0.md in section \"#global-projects\""
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
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
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
|
2013-01-09 18:08:15 -05:00
|
|
|
namespace :sidekiq do
|
2013-01-09 01:14:05 -05: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
|
2012-12-13 06:11:41 -05:00
|
|
|
puts "yes".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
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
|
2013-09-27 06:57:05 -04:00
|
|
|
puts '1'.green
|
|
|
|
else
|
2013-10-17 05:58:03 -04:00
|
|
|
puts "#{process_count}".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
|
2014-02-25 06:12:09 -05:00
|
|
|
ps_ux, _ = Gitlab::Popen.popen(%W(ps ux))
|
|
|
|
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
|
|
|
|
|
2013-11-28 09:20:40 -05:00
|
|
|
namespace :ldap do
|
2013-12-03 12:51:21 -05:00
|
|
|
task :check, [:limit] => :environment do |t, 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?
|
2013-12-03 12:51:21 -05:00
|
|
|
print_users(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
|
|
|
|
|
2013-12-03 12:51:21 -05:00
|
|
|
def print_users(limit)
|
2014-01-21 05:05:03 -05:00
|
|
|
puts "LDAP users with access to your GitLab server (only showing the first #{limit} results)"
|
2013-11-28 09:20:40 -05:00
|
|
|
|
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}"
|
2014-10-22 04:11:18 -04:00
|
|
|
Gitlab::LDAP::Adapter.open(server) do |adapter|
|
2014-10-21 11:26:40 -04:00
|
|
|
users = adapter.users(adapter.config.uid, '*', 100)
|
|
|
|
users.each do |user|
|
|
|
|
puts "\tDN: #{user.dn}\t #{adapter.config.uid}: #{user.uid}"
|
|
|
|
end
|
|
|
|
end
|
2014-03-26 10:38:14 -04:00
|
|
|
end
|
2013-11-28 09:20:40 -05:00
|
|
|
end
|
|
|
|
end
|
2012-12-13 06:11:41 -05:00
|
|
|
|
|
|
|
# Helper methods
|
|
|
|
##########################
|
|
|
|
|
2012-12-22 19:33:58 -05:00
|
|
|
def fix_and_rerun
|
2012-12-13 06:11:41 -05:00
|
|
|
puts " Please #{"fix the error above"} and rerun the checks.".red
|
|
|
|
end
|
|
|
|
|
|
|
|
def for_more_information(*sources)
|
|
|
|
sources = sources.shift if sources.first.is_a?(Array)
|
|
|
|
|
|
|
|
puts " For more information see:".blue
|
|
|
|
sources.each do |source|
|
|
|
|
puts " #{source}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def finished_checking(component)
|
|
|
|
puts ""
|
|
|
|
puts "Checking #{component.yellow} ... #{"Finished".green}"
|
|
|
|
puts ""
|
|
|
|
end
|
|
|
|
|
|
|
|
def see_database_guide
|
|
|
|
"doc/install/databases.md"
|
|
|
|
end
|
|
|
|
|
|
|
|
def see_installation_guide_section(section)
|
|
|
|
"doc/install/installation.md in section \"#{section}\""
|
|
|
|
end
|
|
|
|
|
2013-01-16 18:09:08 -05:00
|
|
|
def sudo_gitlab(command)
|
|
|
|
"sudo -u #{gitlab_user} -H #{command}"
|
|
|
|
end
|
|
|
|
|
2013-10-04 05:18:44 -04:00
|
|
|
def gitlab_user
|
|
|
|
Gitlab.config.gitlab.user
|
|
|
|
end
|
|
|
|
|
2012-12-13 06:11:41 -05:00
|
|
|
def start_checking(component)
|
|
|
|
puts "Checking #{component.yellow} ..."
|
|
|
|
puts ""
|
|
|
|
end
|
|
|
|
|
|
|
|
def try_fixing_it(*steps)
|
|
|
|
steps = steps.shift if steps.first.is_a?(Array)
|
|
|
|
|
|
|
|
puts " Try fixing it:".blue
|
|
|
|
steps.each do |step|
|
|
|
|
puts " #{step}"
|
|
|
|
end
|
|
|
|
end
|
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
|
2013-05-08 01:19:51 -04:00
|
|
|
puts "OK (#{current_version})".green
|
2013-03-12 06:53:07 -04:00
|
|
|
else
|
2013-05-08 01:19:51 -04:00
|
|
|
puts "FAIL. Please update gitlab-shell to #{required_version} from #{current_version}".red
|
2013-03-12 06:53:07 -04:00
|
|
|
end
|
|
|
|
end
|
2013-05-06 08:08:53 -04:00
|
|
|
|
2014-07-23 04:44:27 -04:00
|
|
|
def check_ruby_version
|
|
|
|
required_version = Gitlab::VersionInfo.new(2, 0, 0)
|
|
|
|
current_version = Gitlab::VersionInfo.parse(run(%W(ruby --version)))
|
|
|
|
|
|
|
|
print "Ruby version >= #{required_version} ? ... "
|
|
|
|
|
|
|
|
if current_version.valid? && required_version <= current_version
|
|
|
|
puts "yes (#{current_version})".green
|
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
|
|
|
"Update your ruby to a version >= #{required_version} from #{current_version}"
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-06 08:08:53 -04:00
|
|
|
def check_git_version
|
2013-05-08 01:19:51 -04:00
|
|
|
required_version = Gitlab::VersionInfo.new(1, 7, 10)
|
2014-02-25 06:12:09 -05:00
|
|
|
current_version = Gitlab::VersionInfo.parse(run(%W(#{Gitlab.config.git.bin_path} --version)))
|
2013-05-07 04:12:44 -04:00
|
|
|
|
2013-05-14 06:55:08 -04:00
|
|
|
puts "Your git bin path is \"#{Gitlab.config.git.bin_path}\""
|
2013-05-07 04:12:44 -04:00
|
|
|
print "Git version >= #{required_version} ? ... "
|
|
|
|
|
2013-06-05 21:10:51 -04:00
|
|
|
if current_version.valid? && required_version <= current_version
|
2013-05-08 01:19:51 -04:00
|
|
|
puts "yes (#{current_version})".green
|
2013-05-06 08:08:53 -04:00
|
|
|
else
|
|
|
|
puts "no".red
|
|
|
|
try_fixing_it(
|
2013-05-07 04:12:44 -04:00
|
|
|
"Update your git to a version >= #{required_version} from #{current_version}"
|
2013-05-06 08:08:53 -04:00
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
2014-06-12 03:28:34 -04:00
|
|
|
|
|
|
|
def omnibus_gitlab?
|
|
|
|
Dir.pwd == '/opt/gitlab/embedded/service/gitlab-rails'
|
|
|
|
end
|
2014-07-07 08:12:06 -04:00
|
|
|
|
2014-07-07 08:19:32 -04:00
|
|
|
def sanitized_message(project)
|
2014-12-22 04:03:52 -05:00
|
|
|
if should_sanitize?
|
2014-07-07 08:19:32 -04:00
|
|
|
"#{project.namespace_id.to_s.yellow}/#{project.id.to_s.yellow} ... "
|
|
|
|
else
|
|
|
|
"#{project.name_with_namespace.yellow} ... "
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-22 04:03:52 -05:00
|
|
|
def should_sanitize?
|
2014-07-07 08:12:06 -04:00
|
|
|
if ENV['SANITIZE'] == "true"
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2012-04-03 18:02:54 -04:00
|
|
|
end
|