2 desc "GITLAB | Check the configuration of GitLab and its environment"
3 task check: %w{gitlab:env:check
4 gitlab:gitlab_shell:check
11 desc "GITLAB | Check the configuration of the GitLab Rails app"
12 task check: :environment do
13 warn_user_is_not_gitlab
14 start_checking "GitLab"
16 check_database_config_exists
17 check_database_is_not_sqlite
18 check_migrations_are_up
19 check_gitlab_config_exists
20 check_gitlab_config_not_outdated
23 check_init_script_exists
24 check_init_script_up_to_date
25 check_projects_have_namespace
26 check_satellites_exist
30 finished_checking "GitLab"
35 ########################
37 def check_database_config_exists
38 print "Database config exists? ... "
40 database_config_file = Rails.root.join("config", "database.yml")
42 if File.exists?(database_config_file)
47 "Copy config/database.yml.<your db> to config/database.yml",
48 "Check that the information in config/database.yml is correct"
52 "http://guides.rubyonrails.org/getting_started.html#configuring-a-database"
58 def check_database_is_not_sqlite
59 print "Database is SQLite ... "
61 database_config_file = Rails.root.join("config", "database.yml")
63 unless File.read(database_config_file) =~ /adapter:\s+sqlite/
68 "https://github.com/gitlabhq/gitlabhq/wiki/Migrate-from-SQLite-to-MySQL",
75 def check_gitlab_config_exists
76 print "GitLab config exists? ... "
78 gitlab_config_file = Rails.root.join("config", "gitlab.yml")
80 if File.exists?(gitlab_config_file)
85 "Copy config/gitlab.yml.example to config/gitlab.yml",
86 "Update config/gitlab.yml to match your setup"
89 see_installation_guide_section "GitLab"
95 def check_gitlab_config_not_outdated
96 print "GitLab config outdated? ... "
98 gitlab_config_file = Rails.root.join("config", "gitlab.yml")
99 unless File.exists?(gitlab_config_file)
100 puts "can't check because of previous errors".magenta
103 # omniauth or ldap could have been deleted from the file
104 unless Gitlab.config['git_host']
109 "Backup your config/gitlab.yml",
110 "Copy config/gitlab.yml.example to config/gitlab.yml",
111 "Update config/gitlab.yml to match your setup"
113 for_more_information(
114 see_installation_guide_section "GitLab"
120 def check_init_script_exists
121 print "Init script exists? ... "
123 script_path = "/etc/init.d/gitlab"
125 if File.exists?(script_path)
130 "Install the init script"
132 for_more_information(
133 see_installation_guide_section "Install Init Script"
139 def check_init_script_up_to_date
140 print "Init script up-to-date? ... "
142 recipe_path = Rails.root.join("lib/support/init.d/", "gitlab")
143 script_path = "/etc/init.d/gitlab"
145 unless File.exists?(script_path)
146 puts "can't check because of previous errors".magenta
150 recipe_content = File.read(recipe_path)
151 script_content = File.read(script_path)
153 if recipe_content == script_content
158 "Redownload the init script"
160 for_more_information(
161 see_installation_guide_section "Install Init Script"
167 def check_migrations_are_up
168 print "All migrations up? ... "
170 migration_status = `bundle exec rake db:migrate:status`
172 unless migration_status =~ /down\s+\d{14}/
177 sudo_gitlab("bundle exec rake db:migrate RAILS_ENV=production")
183 def check_satellites_exist
184 print "Projects have satellites? ... "
186 unless Project.count > 0
187 puts "can't check, you have no projects".magenta
192 Project.find_each(batch_size: 100) do |project|
193 print "#{project.name_with_namespace.yellow} ... "
195 if project.satellite.exists?
197 elsif project.empty_repo?
198 puts "can't create, repository is empty".magenta
202 sudo_gitlab("bundle exec rake gitlab:satellites:create RAILS_ENV=production"),
203 "If necessary, remove the tmp/repo_satellites directory ...",
204 "... and rerun the above command"
206 for_more_information(
207 "doc/raketasks/maintenance.md "
214 def check_log_writable
215 print "Log directory writable? ... "
217 log_path = Rails.root.join("log")
219 if File.writable?(log_path)
224 "sudo chown -R gitlab #{log_path}",
225 "sudo chmod -R u+rwX #{log_path}"
227 for_more_information(
228 see_installation_guide_section "GitLab"
234 def check_tmp_writable
235 print "Tmp directory writable? ... "
237 tmp_path = Rails.root.join("tmp")
239 if File.writable?(tmp_path)
244 "sudo chown -R gitlab #{tmp_path}",
245 "sudo chmod -R u+rwX #{tmp_path}"
247 for_more_information(
248 see_installation_guide_section "GitLab"
254 def check_redis_version
255 print "Redis version >= 2.0.0? ... "
257 if run_and_match("redis-cli --version", /redis-cli 2.\d.\d/)
262 "Update your redis server to a version >= 2.0.0"
264 for_more_information(
265 "gitlab-public-wiki/wiki/Trouble-Shooting-Guide in section sidekiq"
275 desc "GITLAB | Check the configuration of the environment"
276 task check: :environment do
277 warn_user_is_not_gitlab
278 start_checking "Environment"
280 check_gitlab_git_config
282 check_python2_version
284 finished_checking "Environment"
289 ########################
291 def check_gitlab_git_config
292 gitlab_user = Gitlab.config.gitlab.user
293 print "Git configured for #{gitlab_user} user? ... "
296 "user.name" => "GitLab",
297 "user.email" => Gitlab.config.gitlab.email_from
299 correct_options = options.map do |name, value|
300 run("git config --global --get #{name}").try(:squish) == value
303 if correct_options.all?
308 sudo_gitlab("git config --global user.name \"#{options["user.name"]}\""),
309 sudo_gitlab("git config --global user.email \"#{options["user.email"]}\"")
311 for_more_information(
312 see_installation_guide_section "GitLab"
318 def check_python2_exists
319 print "Has python2? ... "
321 # Python prints its version to STDERR
322 # so we can't just use run("python2 --version")
323 if run_and_match("which python2", /python2$/)
328 "Make sure you have Python 2.5+ installed",
331 for_more_information(
332 see_installation_guide_section "Packages / Dependencies"
338 def check_python2_version
339 print "python2 is supported version? ... "
341 # Python prints its version to STDERR
342 # so we can't just use run("python2 --version")
344 unless run_and_match("which python2", /python2$/)
345 puts "can't check because of previous errors".magenta
349 if `python2 --version 2>&1` =~ /2\.[567]\.\d/
354 "Make sure you have Python 2.5+ installed",
357 for_more_information(
358 see_installation_guide_section "Packages / Dependencies"
367 namespace :gitlab_shell do
368 desc "GITLAB | Check the configuration of GitLab Shell"
369 task check: :environment do
370 warn_user_is_not_gitlab
371 start_checking "GitLab Shell"
374 check_repo_base_exists
375 check_repo_base_is_not_symlink
376 check_repo_base_user_and_group
377 check_repo_base_permissions
378 check_update_hook_is_up_to_date
379 check_repos_update_hooks_is_link
380 check_gitlab_shell_self_test
382 finished_checking "GitLab Shell"
387 ########################
390 def check_update_hook_is_up_to_date
391 print "update hook up-to-date? ... "
394 gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path
395 gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file)
397 if File.exists?(gitlab_shell_hook_file)
401 puts "Could not find #{gitlab_shell_hook_file}"
403 'Check the hooks_path in config/gitlab.yml',
404 'Check your gitlab-shell installation'
406 for_more_information(
407 see_installation_guide_section "GitLab Shell"
412 def check_repo_base_exists
413 print "Repo base directory exists? ... "
415 repo_base_path = Gitlab.config.gitlab_shell.repos_path
417 if File.exists?(repo_base_path)
421 puts "#{repo_base_path} is missing".red
423 "This should have been created when setting up GitLab Shell.",
424 "Make sure it's set correctly in config/gitlab.yml",
425 "Make sure GitLab Shell is installed correctly."
427 for_more_information(
428 see_installation_guide_section "GitLab Shell"
434 def check_repo_base_is_not_symlink
435 print "Repo base directory is a symlink? ... "
437 repo_base_path = Gitlab.config.gitlab_shell.repos_path
438 unless File.exists?(repo_base_path)
439 puts "can't check because of previous errors".magenta
443 unless File.symlink?(repo_base_path)
448 "Make sure it's set to the real directory in config/gitlab.yml"
454 def check_repo_base_permissions
455 print "Repo base access is drwxrws---? ... "
457 repo_base_path = Gitlab.config.gitlab_shell.repos_path
458 unless File.exists?(repo_base_path)
459 puts "can't check because of previous errors".magenta
463 if File.stat(repo_base_path).mode.to_s(8).ends_with?("2770")
468 "sudo chmod -R ug+rwX,o-rwx #{repo_base_path}",
469 "sudo chmod -R ug-s #{repo_base_path}",
470 "find #{repo_base_path} -type d -print0 | sudo xargs -0 chmod g+s"
472 for_more_information(
473 see_installation_guide_section "GitLab Shell"
479 def check_repo_base_user_and_group
480 gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user
481 gitlab_shell_owner_group = Gitlab.config.gitlab_shell.owner_group
482 print "Repo base owned by #{gitlab_shell_ssh_user}:#{gitlab_shell_owner_group}? ... "
484 repo_base_path = Gitlab.config.gitlab_shell.repos_path
485 unless File.exists?(repo_base_path)
486 puts "can't check because of previous errors".magenta
490 uid = uid_for(gitlab_shell_ssh_user)
491 gid = gid_for(gitlab_shell_owner_group)
492 if File.stat(repo_base_path).uid == uid && File.stat(repo_base_path).gid == gid
496 puts " User id for #{gitlab_shell_ssh_user}: #{uid}. Groupd id for #{gitlab_shell_owner_group}: #{gid}".blue
498 "sudo chown -R #{gitlab_shell_ssh_user}:#{gitlab_shell_owner_group} #{repo_base_path}"
500 for_more_information(
501 see_installation_guide_section "GitLab Shell"
507 def check_repos_update_hooks_is_link
508 print "update hooks in repos are links: ... "
511 gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path
512 gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file)
513 gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user
515 unless File.exists?(gitlab_shell_hook_file)
516 puts "can't check because of previous errors".magenta
520 unless Project.count > 0
521 puts "can't check, you have no projects".magenta
526 Project.find_each(batch_size: 100) do |project|
527 print "#{project.name_with_namespace.yellow} ... "
529 if project.empty_repo?
530 puts "repository is empty".magenta
532 project_hook_file = File.join(project.repository.path_to_repo, "hooks", hook_file)
534 unless File.exists?(project_hook_file)
537 "sudo -u #{gitlab_shell_ssh_user} ln -sf #{gitlab_shell_hook_file} #{project_hook_file}"
539 for_more_information(
540 "#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh"
546 if File.lstat(project_hook_file).symlink? &&
547 File.realpath(project_hook_file) == File.realpath(gitlab_shell_hook_file)
550 puts "not a link to GitLab Shell's hook".red
552 "sudo -u #{gitlab_shell_ssh_user} ln -sf #{gitlab_shell_hook_file} #{project_hook_file}"
554 for_more_information(
555 "lib/support/rewrite-hooks.sh"
563 def check_gitlab_shell_self_test
564 gitlab_shell_repo_base = File.expand_path('gitlab-shell', gitlab_shell_user_home)
565 check_cmd = File.expand_path('bin/check', gitlab_shell_repo_base)
566 puts "Running #{check_cmd}"
567 if system(check_cmd, chdir: gitlab_shell_repo_base)
568 puts 'gitlab-shell self-check successful'.green
570 puts 'gitlab-shell self-check failed'.red
572 'Make sure GitLab is running;',
573 'Check the gitlab-shell configuration file:',
574 sudo_gitlab("editor #{File.expand_path('config.yml', gitlab_shell_repo_base)}")
580 def check_projects_have_namespace
581 print "projects have namespace: ... "
583 unless Project.count > 0
584 puts "can't check, you have no projects".magenta
589 Project.find_each(batch_size: 100) do |project|
590 print "#{project.name_with_namespace.yellow} ... "
597 "Migrate global projects"
599 for_more_information(
600 "doc/update/5.4-to-6.0.md in section \"#global-projects\""
608 ########################
610 def gitlab_shell_user_home
611 File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}")
614 def gitlab_shell_version
615 gitlab_shell_version_file = "#{gitlab_shell_user_home}/gitlab-shell/VERSION"
616 if File.readable?(gitlab_shell_version_file)
617 File.read(gitlab_shell_version_file)
621 def has_gitlab_shell3?
622 gitlab_shell_version.try(:start_with?, "v3.")
628 namespace :sidekiq do
629 desc "GITLAB | Check the configuration of Sidekiq"
630 task check: :environment do
631 warn_user_is_not_gitlab
632 start_checking "Sidekiq"
634 check_sidekiq_running
635 only_one_sidekiq_running
637 finished_checking "Sidekiq"
642 ########################
644 def check_sidekiq_running
645 print "Running? ... "
647 if sidekiq_process_match
652 sudo_gitlab("bundle exec rake sidekiq:start RAILS_ENV=production")
654 for_more_information(
655 see_installation_guide_section("Install Init Script"),
656 "see log/sidekiq.log for possible errors"
662 def only_one_sidekiq_running
663 sidekiq_match = sidekiq_process_match
664 return unless sidekiq_match
666 print 'Number of Sidekiq processes ... '
667 if sidekiq_match.length == 1
670 puts "#{sidekiq_match.length}".red
672 'sudo service gitlab stop',
673 'sudo pkill -f sidekiq',
674 'sleep 10 && sudo pkill -9 -f sidekiq',
675 'sudo service gitlab start'
681 def sidekiq_process_match
682 run_and_match("ps ux | grep -i sidekiq", /(sidekiq \d+\.\d+\.\d+.+$)/)
688 ##########################
691 puts " Please #{"fix the error above"} and rerun the checks.".red
694 def for_more_information(*sources)
695 sources = sources.shift if sources.first.is_a?(Array)
697 puts " For more information see:".blue
698 sources.each do |source|
703 def finished_checking(component)
705 puts "Checking #{component.yellow} ... #{"Finished".green}"
709 def see_database_guide
710 "doc/install/databases.md"
713 def see_installation_guide_section(section)
714 "doc/install/installation.md in section \"#{section}\""
717 def sudo_gitlab(command)
718 gitlab_user = Gitlab.config.gitlab.user
719 "sudo -u #{gitlab_user} -H #{command}"
722 def start_checking(component)
723 puts "Checking #{component.yellow} ..."
727 def try_fixing_it(*steps)
728 steps = steps.shift if steps.first.is_a?(Array)
730 puts " Try fixing it:".blue
736 def check_gitlab_shell
737 required_version = Gitlab::VersionInfo.new(1, 7, 1)
738 current_version = Gitlab::VersionInfo.parse(gitlab_shell_version)
740 print "GitLab Shell version >= #{required_version} ? ... "
741 if current_version.valid? && required_version <= current_version
742 puts "OK (#{current_version})".green
744 puts "FAIL. Please update gitlab-shell to #{required_version} from #{current_version}".red
748 def check_git_version
749 required_version = Gitlab::VersionInfo.new(1, 7, 10)
750 current_version = Gitlab::VersionInfo.parse(run("#{Gitlab.config.git.bin_path} --version"))
752 puts "Your git bin path is \"#{Gitlab.config.git.bin_path}\""
753 print "Git version >= #{required_version} ? ... "
755 if current_version.valid? && required_version <= current_version
756 puts "yes (#{current_version})".green
760 "Update your git to a version >= #{required_version} from #{current_version}"