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 @@ ...@@ -2,16 +2,25 @@
module SystemCheck module SystemCheck
module App module App
class InitScriptUpToDateCheck < SystemCheck::BaseCheck class SystemdUnitFilesOrInitScriptUpToDateCheck < SystemCheck::BaseCheck
SCRIPT_PATH = '/etc/init.d/gitlab' 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_name 'Systemd unit files or init script up-to-date?'
set_skip_reason 'skipped (omnibus-gitlab has no init script)' set_skip_reason 'skipped (omnibus-gitlab has neither init script nor systemd units)'
def skip? def skip?
return true if omnibus_gitlab? 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" self.skip_reason = "can't check because of previous errors"
true true
...@@ -19,20 +28,19 @@ module SystemCheck ...@@ -19,20 +28,19 @@ module SystemCheck
end end
def check? def check?
recipe_path = Rails.root.join('lib/support/init.d/', 'gitlab') if unit_files_exist?
return unit_files_up_to_date?
recipe_content = File.read(recipe_path) end
script_content = File.read(SCRIPT_PATH)
recipe_content == script_content init_file_up_to_date?
end end
def show_error def show_error
try_fixing_it( try_fixing_it(
'Re-download the init script' 'Install the Service'
) )
for_more_information( for_more_information(
see_installation_guide_section('Install Init Script') see_installation_guide_section('Install the Service')
) )
fix_and_rerun fix_and_rerun
end end
...@@ -42,6 +50,31 @@ module SystemCheck ...@@ -42,6 +50,31 @@ module SystemCheck
def init_file_exists? def init_file_exists?
File.exist?(SCRIPT_PATH) File.exist?(SCRIPT_PATH)
end 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 end
end end
...@@ -2,20 +2,21 @@ ...@@ -2,20 +2,21 @@
module SystemCheck module SystemCheck
module IncomingEmail module IncomingEmail
class InitdConfiguredCheck < SystemCheck::BaseCheck class MailRoomEnabledCheck < SystemCheck::BaseCheck
set_name 'Init.d configured correctly?' include ::SystemCheck::InitHelpers
set_name 'Mailroom enabled?'
def skip? def skip?
omnibus_gitlab? omnibus_gitlab?
end end
def check? def check?
mail_room_configured? mail_room_enabled? || mail_room_configured?
end end
def show_error def show_error
try_fixing_it( try_fixing_it(
'Enable mail_room in the init.d configuration.' 'Enable mail_room'
) )
for_more_information( for_more_information(
'doc/administration/reply_by_email.md' 'doc/administration/reply_by_email.md'
...@@ -25,6 +26,13 @@ module SystemCheck ...@@ -25,6 +26,13 @@ module SystemCheck
private 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? def mail_room_configured?
path = '/etc/default/gitlab' path = '/etc/default/gitlab'
File.exist?(path) && File.read(path).include?('mail_room_enabled=true') File.exist?(path) && File.read(path).include?('mail_room_enabled=true')
......
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
module SystemCheck module SystemCheck
module IncomingEmail module IncomingEmail
class MailRoomRunningCheck < SystemCheck::BaseCheck class MailRoomRunningCheck < SystemCheck::BaseCheck
include ::SystemCheck::InitHelpers
set_name 'MailRoom running?' set_name 'MailRoom running?'
def skip? def skip?
return true if omnibus_gitlab? 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" self.skip_reason = "can't check because of previous errors"
true true
end end
...@@ -20,10 +21,10 @@ module SystemCheck ...@@ -20,10 +21,10 @@ module SystemCheck
def show_error def show_error
try_fixing_it( try_fixing_it(
sudo_gitlab('RAILS_ENV=production bin/mail_room start') 'Start mail_room'
) )
for_more_information( for_more_information(
see_installation_guide_section('Install Init Script'), 'doc/administration/incoming_email.md',
'see log/mail_room.log for possible errors' 'see log/mail_room.log for possible errors'
) )
fix_and_rerun fix_and_rerun
...@@ -31,6 +32,13 @@ module SystemCheck ...@@ -31,6 +32,13 @@ module SystemCheck
private 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? def mail_room_configured?
path = '/etc/default/gitlab' path = '/etc/default/gitlab'
File.exist?(path) && File.read(path).include?('mail_room_enabled=true') File.exist?(path) && File.read(path).include?('mail_room_enabled=true')
......
...@@ -14,7 +14,7 @@ module SystemCheck ...@@ -14,7 +14,7 @@ module SystemCheck
end end
if Rails.env.production? if Rails.env.production?
checks << SystemCheck::IncomingEmail::InitdConfiguredCheck checks << SystemCheck::IncomingEmail::MailRoomEnabledCheck
checks << SystemCheck::IncomingEmail::MailRoomRunningCheck checks << SystemCheck::IncomingEmail::MailRoomRunningCheck
end 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 ...@@ -23,8 +23,8 @@ module SystemCheck
SystemCheck::App::UploadsDirectoryExistsCheck, SystemCheck::App::UploadsDirectoryExistsCheck,
SystemCheck::App::UploadsPathPermissionCheck, SystemCheck::App::UploadsPathPermissionCheck,
SystemCheck::App::UploadsPathTmpPermissionCheck, SystemCheck::App::UploadsPathTmpPermissionCheck,
SystemCheck::App::InitScriptExistsCheck, SystemCheck::App::SystemdUnitFilesOrInitScriptExistCheck,
SystemCheck::App::InitScriptUpToDateCheck, SystemCheck::App::SystemdUnitFilesOrInitScriptUpToDateCheck,
SystemCheck::App::ProjectsHaveNamespaceCheck, SystemCheck::App::ProjectsHaveNamespaceCheck,
SystemCheck::App::RedisVersionCheck, SystemCheck::App::RedisVersionCheck,
SystemCheck::App::RubyVersionCheck, SystemCheck::App::RubyVersionCheck,
......
...@@ -39,6 +39,12 @@ module SystemCheck ...@@ -39,6 +39,12 @@ module SystemCheck
if (cluster_count == 1 && worker_count > 0) || (cluster_count == 0 && worker_count == 1) if (cluster_count == 1 && worker_count > 0) || (cluster_count == 0 && worker_count == 1)
$stdout.puts "#{cluster_count}/#{worker_count}".color(:green) $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 else
$stdout.puts "#{cluster_count}/#{worker_count}".color(:red) $stdout.puts "#{cluster_count}/#{worker_count}".color(:red)
try_fixing_it( try_fixing_it(
......
...@@ -28,7 +28,7 @@ RSpec.describe SystemCheck::IncomingEmailCheck do ...@@ -28,7 +28,7 @@ RSpec.describe SystemCheck::IncomingEmailCheck do
it 'runs IMAP and mailroom checks' do it 'runs IMAP and mailroom checks' do
expect(SystemCheck).to receive(:run).with('Reply by email', [ expect(SystemCheck).to receive(:run).with('Reply by email', [
SystemCheck::IncomingEmail::ImapAuthenticationCheck, SystemCheck::IncomingEmail::ImapAuthenticationCheck,
SystemCheck::IncomingEmail::InitdConfiguredCheck, SystemCheck::IncomingEmail::MailRoomEnabledCheck,
SystemCheck::IncomingEmail::MailRoomRunningCheck SystemCheck::IncomingEmail::MailRoomRunningCheck
]) ])
...@@ -43,7 +43,7 @@ RSpec.describe SystemCheck::IncomingEmailCheck do ...@@ -43,7 +43,7 @@ RSpec.describe SystemCheck::IncomingEmailCheck do
it 'runs mailroom checks' do it 'runs mailroom checks' do
expect(SystemCheck).to receive(:run).with('Reply by email', [ expect(SystemCheck).to receive(:run).with('Reply by email', [
SystemCheck::IncomingEmail::InitdConfiguredCheck, SystemCheck::IncomingEmail::MailRoomEnabledCheck,
SystemCheck::IncomingEmail::MailRoomRunningCheck 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