Commit 18828c78 authored by Joerg Behrmann's avatar Joerg Behrmann

Rework rake checks for both systemd and SysV source installs

Rewrite the rake and spec checks so that both installations using
systemd units and the SysV init script are supported.
parent 1db87da7
# frozen_string_literal: true
module SystemCheck
module App
class InitScriptExistsCheck < SystemCheck::BaseCheck
set_name 'Init script exists?'
set_skip_reason 'skipped (omnibus-gitlab has no init script)'
def skip?
omnibus_gitlab?
end
def check?
script_path = '/etc/init.d/gitlab'
File.exist?(script_path)
end
def show_error
try_fixing_it(
'Install the init script'
)
for_more_information(
see_installation_guide_section('Install Init Script')
)
fix_and_rerun
end
end
end
end
# frozen_string_literal: true
module SystemCheck
module App
class SystemdUnitFilesOrInitScriptExistCheck < SystemCheck::BaseCheck
set_name 'Systemd unit files or init script exist?'
set_skip_reason 'skipped (omnibus-gitlab has neither init script nor systemd units)'
def skip?
omnibus_gitlab?
end
def check?
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'
]
script_path = '/etc/init.d/gitlab'
unit_paths.all? { |s| File.exist?(s) } || File.exist?(script_path)
end
def show_error
try_fixing_it(
'Install the Service'
)
for_more_information(
see_installation_guide_section('Install the Service')
)
fix_and_rerun
end
end
end
end
......@@ -2,16 +2,25 @@
module SystemCheck
module App
class InitScriptUpToDateCheck < SystemCheck::BaseCheck
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 'Init script up-to-date?'
set_skip_reason 'skipped (omnibus-gitlab has no init script)'
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 init_file_exists?
unless unit_files_exist? || init_file_exists?
self.skip_reason = "can't check because of previous errors"
true
......@@ -19,20 +28,19 @@ module SystemCheck
end
def check?
recipe_path = Rails.root.join('lib/support/init.d/', 'gitlab')
recipe_content = File.read(recipe_path)
script_content = File.read(SCRIPT_PATH)
if unit_files_exist?
return unit_files_up_to_date?
end
recipe_content == script_content
init_file_up_to_date?
end
def show_error
try_fixing_it(
'Re-download the init script'
'Install the Service'
)
for_more_information(
see_installation_guide_section('Install Init Script')
see_installation_guide_section('Install the Service')
)
fix_and_rerun
end
......@@ -42,6 +50,31 @@ module SystemCheck
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
......@@ -2,20 +2,21 @@
module SystemCheck
module IncomingEmail
class InitdConfiguredCheck < SystemCheck::BaseCheck
set_name 'Init.d configured correctly?'
class MailRoomEnabledCheck < SystemCheck::BaseCheck
include ::SystemCheck::InitHelpers
set_name 'Mailroom enabled?'
def skip?
omnibus_gitlab?
end
def check?
mail_room_configured?
mail_room_enabled? || mail_room_configured?
end
def show_error
try_fixing_it(
'Enable mail_room in the init.d configuration.'
'Enable mail_room'
)
for_more_information(
'doc/administration/reply_by_email.md'
......@@ -25,6 +26,13 @@ module SystemCheck
private
def mail_room_enabled?
target = '/usr/local/lib/systemd/system/gitlab.target'
service = '/usr/local/lib/systemd/system/gitlab-mailroom.service'
File.exist?(target) && File.exist?(service) && systemd_get_wants('gitlab.target').include?("gitlab-mailroom.service")
end
def mail_room_configured?
path = '/etc/default/gitlab'
File.exist?(path) && File.read(path).include?('mail_room_enabled=true')
......
......@@ -3,12 +3,13 @@
module SystemCheck
module IncomingEmail
class MailRoomRunningCheck < SystemCheck::BaseCheck
include ::SystemCheck::InitHelpers
set_name 'MailRoom running?'
def skip?
return true if omnibus_gitlab?
unless mail_room_configured?
unless mail_room_enabled? || mail_room_configured?
self.skip_reason = "can't check because of previous errors"
true
end
......@@ -20,10 +21,10 @@ module SystemCheck
def show_error
try_fixing_it(
sudo_gitlab('RAILS_ENV=production bin/mail_room start')
'Start mail_room'
)
for_more_information(
see_installation_guide_section('Install Init Script'),
'doc/administration/incoming_email.md',
'see log/mail_room.log for possible errors'
)
fix_and_rerun
......@@ -31,6 +32,13 @@ module SystemCheck
private
def mail_room_enabled?
target = '/usr/local/lib/systemd/system/gitlab.target'
service = '/usr/local/lib/systemd/system/gitlab-mailroom.service'
File.exist?(target) && File.exist?(service) && systemd_get_wants('gitlab.target').include?("gitlab-mailroom.service")
end
def mail_room_configured?
path = '/etc/default/gitlab'
File.exist?(path) && File.read(path).include?('mail_room_enabled=true')
......
......@@ -14,7 +14,7 @@ module SystemCheck
end
if Rails.env.production?
checks << SystemCheck::IncomingEmail::InitdConfiguredCheck
checks << SystemCheck::IncomingEmail::MailRoomEnabledCheck
checks << SystemCheck::IncomingEmail::MailRoomRunningCheck
end
......
# frozen_string_literal: true
require 'open3'
module SystemCheck
module InitHelpers
# Return the Wants= of a unit, empty if the unit doesn't exist
def systemd_get_wants(unitname)
stdout, _stderr, status = Open3.capture3("systemctl", "--no-pager", "show", unitname)
unless status
return []
end
wantsline = stdout.lines.find { |line| line.start_with?("Wants=") }
unless wantsline
return []
end
wantsline.delete_prefix("Wants=").strip.split
end
end
end
......@@ -23,8 +23,8 @@ module SystemCheck
SystemCheck::App::UploadsDirectoryExistsCheck,
SystemCheck::App::UploadsPathPermissionCheck,
SystemCheck::App::UploadsPathTmpPermissionCheck,
SystemCheck::App::InitScriptExistsCheck,
SystemCheck::App::InitScriptUpToDateCheck,
SystemCheck::App::SystemdUnitFilesOrInitScriptExistCheck,
SystemCheck::App::SystemdUnitFilesOrInitScriptUpToDateCheck,
SystemCheck::App::ProjectsHaveNamespaceCheck,
SystemCheck::App::RedisVersionCheck,
SystemCheck::App::RubyVersionCheck,
......
......@@ -39,6 +39,12 @@ module SystemCheck
if (cluster_count == 1 && worker_count > 0) || (cluster_count == 0 && worker_count == 1)
$stdout.puts "#{cluster_count}/#{worker_count}".color(:green)
elsif File.symlink?('/run/systemd/units/invocation:gitlab-sidekiq.service')
$stdout.puts "#{cluster_count}/#{worker_count}".color(:red)
try_fixing_it(
'sudo systemctl restart gitlab-sidekiq.service'
)
fix_and_rerun
else
$stdout.puts "#{cluster_count}/#{worker_count}".color(:red)
try_fixing_it(
......
......@@ -28,7 +28,7 @@ RSpec.describe SystemCheck::IncomingEmailCheck do
it 'runs IMAP and mailroom checks' do
expect(SystemCheck).to receive(:run).with('Reply by email', [
SystemCheck::IncomingEmail::ImapAuthenticationCheck,
SystemCheck::IncomingEmail::InitdConfiguredCheck,
SystemCheck::IncomingEmail::MailRoomEnabledCheck,
SystemCheck::IncomingEmail::MailRoomRunningCheck
])
......@@ -43,7 +43,7 @@ RSpec.describe SystemCheck::IncomingEmailCheck do
it 'runs mailroom checks' do
expect(SystemCheck).to receive(:run).with('Reply by email', [
SystemCheck::IncomingEmail::InitdConfiguredCheck,
SystemCheck::IncomingEmail::MailRoomEnabledCheck,
SystemCheck::IncomingEmail::MailRoomRunningCheck
])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment