Welcome to mirror list, hosted at ThFree Co, Russian Federation.

systemd_unit_files_or_init_script_up_to_date_check.rb « app « system_check « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10bc772a83c57c4e1fe916b695505d3ab60f1b4b (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# frozen_string_literal: true

module SystemCheck
  module App
    class SystemdUnitFilesOrInitScriptUpToDateCheck < SystemCheck::BaseCheck
      SCRIPT_PATH = '/etc/init.d/gitlab'
      UNIT_PATHS = [
        '/usr/local/lib/systemd/system/gitlab-gitaly.service',
        '/usr/local/lib/systemd/system/gitlab-mailroom.service',
        '/usr/local/lib/systemd/system/gitlab-puma.service',
        '/usr/local/lib/systemd/system/gitlab-sidekiq.service',
        '/usr/local/lib/systemd/system/gitlab.slice',
        '/usr/local/lib/systemd/system/gitlab.target',
        '/usr/local/lib/systemd/system/gitlab-workhorse.service'
      ].freeze

      set_name 'Systemd unit files or init script up-to-date?'
      set_skip_reason 'skipped (omnibus-gitlab has neither init script nor systemd units)'

      def skip?
        return true if omnibus_gitlab?

        unless unit_files_exist? || init_file_exists?
          self.skip_reason = "can't check because of previous errors"

          true
        end
      end

      def check?
        if unit_files_exist?
          return unit_files_up_to_date?
        end

        init_file_up_to_date?
      end

      def show_error
        try_fixing_it(
          'Install the Service'
        )
        for_more_information(
          see_installation_guide_section('Install the Service')
        )
        fix_and_rerun
      end

      private

      def init_file_exists?
        File.exist?(SCRIPT_PATH)
      end

      def unit_files_exist?
        UNIT_PATHS.all? { |s| File.exist?(s) }
      end

      def init_file_up_to_date?
        recipe_path = Rails.root.join('lib/support/init.d/', 'gitlab')

        recipe_content = File.read(recipe_path)
        script_content = File.read(SCRIPT_PATH)

        recipe_content == script_content
      end

      def unit_files_up_to_date?
        UNIT_PATHS.all? do |unit|
          unit_name = File.basename(unit)
          recipe_path = Rails.root.join('lib/support/systemd/', unit_name)

          recipe_content = File.read(recipe_path)
          unit_content = File.read(unit)

          recipe_content == unit_content
        end
      end
    end
  end
end