Project

General

Profile

« Previous | Next » 

Revision d9f3f547

Added by John Mitsch almost 6 years ago

Fixes #23615 - Redirect katello service

Katello-service functionality has moved to foreman-maintain. We
can redirect katello-service there since it uses the same arguments.
Katello-service is used pretty widely in documenation and scripts,
I don't see a need to deprecate this just yet (we always can later).
I aligned the issue with foreman 1.19(katello 3.8), so katello
3.7 will still have the original katello-service script.

View differences:

packages/katello/katello/katello-service
#!/usr/bin/env ruby
#!/bin/sh
require 'optparse'
REDIRECT_MESSAGE="Redirecting to 'foreman-maintain service'"
ACTIONS = ['restart', 'stop', 'start', 'status', 'list', 'enable', 'disable']
SERVICES = {
'rh-mongodb34-mongod' => 5,
'postgresql' => 5,
'qpidd' => 10,
'qdrouterd' => 10,
'squid' => 10,
'tomcat' => 20,
'pulp_workers' => 20,
'pulp_celerybeat' => 20,
'pulp_resource_manager' => 20,
'pulp_streamer' => 20,
'foreman-proxy' => 20,
'smart_proxy_dynflow_core' => 20,
'httpd' => 30,
'puppetserver' => 30,
'dynflowd' => 30,
'goferd' => 30
}
echo "$REDIRECT_MESSAGE"
foreman-maintain service $*
@options = {:excluded => []}
OptionParser.new do |opts|
opts.banner = "Usage: katello-service [options] [#{ACTIONS.join('|')}]"
opts.on("--exclude [SERVICES]", Array, "A comma-separated list of services to skip") do |exclude|
@options[:excluded] = exclude
end
opts.on("--only [SERVICES]", Array, "A comma-separated list of services to include") do |only|
@options[:only] = only
end
opts.parse!
if ARGV.length == 0 || ARGV.length != 1
puts opts
exit
else
opts.abort("Received unsupported arguments: #{ARGV[0]}") unless ACTIONS.include?(ARGV[0])
end
@options[:action] = ARGV[0]
end
def service_exists?(service)
systemd = `systemctl is-enabled #{service} 2>&1`.strip
systemd == 'enabled' || systemd == 'disabled'
end
def services_by_priority(descending = false)
services = if @options.include?(:only)
SERVICES.sort_by { |_, value| value }.map { |service| service[0] } & @options[:only]
else
SERVICES.sort_by { |_, value| value }.map { |service| service[0] } - @options[:excluded]
end
descending ? services.reverse : services
end
def list_services
regex = services_by_priority.map { |service| "^#{service}.service" }.join('\|')
puts `systemctl list-unit-files | grep '#{regex}'`
end
def manage_services(action)
failures = []
`logger -t #{$0} -p daemon.info '*** #{action} initiated ***'`
services_by_priority(action == 'stop').each do |service|
if service_exists?(service)
puts "systemctl #{action} #{service}.service"
puts `systemctl #{action} #{service}.service`
failures << service unless $?.success?
end
end
if failures.empty?
puts "Success!"
`logger -t #{$0} -p daemon.info '*** #{action} finished successfuly ***'`
else
puts "Some services failed to #{action}: #{failures.join(',')}"
`logger -t #{$0} -p daemon.warning '*** #{action} failed: #{failures.join(',')} ***'`
exit 1
end
end
case @options[:action]
when 'list'
list_services
when 'restart'
%w(stop start).each { |action| manage_services action }
else
manage_services @options[:action]
end

Also available in: Unified diff