2018-11-27 19:08:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SystemCheck
|
|
|
|
# Used by gitlab:sidekiq:check rake task
|
|
|
|
class SidekiqCheck < BaseCheck
|
|
|
|
set_name 'Sidekiq:'
|
|
|
|
|
|
|
|
def multi_check
|
|
|
|
check_sidekiq_running
|
|
|
|
only_one_sidekiq_running
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_sidekiq_running
|
|
|
|
$stdout.print "Running? ... "
|
|
|
|
|
2021-03-08 13:09:12 -05:00
|
|
|
if sidekiq_worker_process_count > 0
|
2018-11-27 19:08:31 -05:00
|
|
|
$stdout.puts "yes".color(:green)
|
|
|
|
else
|
|
|
|
$stdout.puts "no".color(:red)
|
|
|
|
try_fixing_it(
|
|
|
|
sudo_gitlab("RAILS_ENV=production bin/background_jobs start")
|
|
|
|
)
|
|
|
|
for_more_information(
|
|
|
|
see_installation_guide_section("Install Init Script"),
|
|
|
|
"see log/sidekiq.log for possible errors"
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def only_one_sidekiq_running
|
2021-03-08 13:09:12 -05:00
|
|
|
worker_count = sidekiq_worker_process_count
|
|
|
|
cluster_count = sidekiq_cluster_process_count
|
|
|
|
return if worker_count == 0
|
2018-11-27 19:08:31 -05:00
|
|
|
|
2021-03-08 13:09:12 -05:00
|
|
|
$stdout.print 'Number of Sidekiq processes (cluster/worker) ... '
|
2018-11-27 19:08:31 -05:00
|
|
|
|
2021-03-08 13:09:12 -05:00
|
|
|
if (cluster_count == 1 && worker_count > 0) || (cluster_count == 0 && worker_count == 1)
|
|
|
|
$stdout.puts "#{cluster_count}/#{worker_count}".color(:green)
|
2021-10-28 11:09:42 -04:00
|
|
|
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
|
2018-11-27 19:08:31 -05:00
|
|
|
else
|
2021-03-08 13:09:12 -05:00
|
|
|
$stdout.puts "#{cluster_count}/#{worker_count}".color(:red)
|
2018-11-27 19:08:31 -05:00
|
|
|
try_fixing_it(
|
|
|
|
'sudo service gitlab stop',
|
|
|
|
"sudo pkill -u #{gitlab_user} -f sidekiq",
|
|
|
|
"sleep 10 && sudo pkill -9 -u #{gitlab_user} -f sidekiq",
|
|
|
|
'sudo service gitlab start'
|
|
|
|
)
|
|
|
|
fix_and_rerun
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-08 13:09:12 -05:00
|
|
|
def sidekiq_worker_process_count
|
2018-11-27 19:08:31 -05:00
|
|
|
ps_ux, _ = Gitlab::Popen.popen(%w(ps uxww))
|
2021-03-08 13:09:12 -05:00
|
|
|
ps_ux.lines.grep(/sidekiq \d+\.\d+\.\d+/).count
|
|
|
|
end
|
|
|
|
|
|
|
|
def sidekiq_cluster_process_count
|
|
|
|
ps_ux, _ = Gitlab::Popen.popen(%w(ps uxww))
|
|
|
|
ps_ux.lines.grep(/sidekiq-cluster/).count
|
2018-11-27 19:08:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|