File: gitlab_shell_check.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (56 lines) | stat: -rw-r--r-- 1,686 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

module SystemCheck
  # Used by gitlab:gitlab_shell:check rake task
  class GitlabShellCheck < BaseCheck
    set_name 'GitLab Shell:'

    def multi_check
      check_gitlab_shell
      check_gitlab_shell_self_test
    end

    private

    def check_gitlab_shell
      required_version = Gitlab::VersionInfo.parse(Gitlab::Shell.version_required)
      current_version = Gitlab::VersionInfo.parse(gitlab_shell_version)

      $stdout.print "GitLab Shell version >= #{required_version} ? ... "
      if current_version.valid? && required_version <= current_version
        $stdout.puts Rainbow("OK (#{current_version})").green
      else
        $stdout.puts Rainbow("FAIL. Please update gitlab-shell to #{required_version} from #{current_version}").red
      end
    end

    def check_gitlab_shell_self_test
      gitlab_shell_repo_base = gitlab_shell_path
      check_cmd = File.expand_path('bin/gitlab-shell-check', gitlab_shell_repo_base)
      $stdout.puts "Running #{check_cmd}"

      if system(check_cmd, chdir: gitlab_shell_repo_base)
        $stdout.puts Rainbow('gitlab-shell self-check successful').green
      else
        $stdout.puts Rainbow('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

    # Helper methods
    ########################

    def gitlab_shell_path
      Gitlab.config.gitlab_shell.path
    end

    def gitlab_shell_version
      Gitlab::Shell.version
    end
  end
end