foreman_maintain 1.0.12 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/definitions/features/capsule.rb +1 -1
- data/definitions/features/foreman_database.rb +7 -1
- data/definitions/features/installer.rb +7 -1
- data/definitions/features/katello.rb +1 -1
- data/definitions/features/satellite.rb +1 -1
- data/definitions/procedures/backup/config_files.rb +25 -10
- data/definitions/procedures/backup/metadata.rb +11 -7
- data/definitions/procedures/backup/offline/foreman_db.rb +30 -9
- data/definitions/procedures/maintenance_mode/disable_maintenance_mode.rb +2 -1
- data/definitions/procedures/maintenance_mode/enable_maintenance_mode.rb +1 -30
- data/definitions/procedures/packages/update.rb +3 -1
- data/definitions/procedures/pulp/remove.rb +49 -13
- data/definitions/procedures/restore/extract_files.rb +4 -0
- data/definitions/procedures/selinux/set_file_security.rb +3 -0
- data/definitions/scenarios/backup.rb +10 -0
- data/definitions/scenarios/packages.rb +2 -2
- data/definitions/scenarios/self_upgrade.rb +10 -67
- data/lib/foreman_maintain/cli/packages_command.rb +26 -7
- data/lib/foreman_maintain/cli/self_upgrade_command.rb +1 -7
- data/lib/foreman_maintain/concerns/base_database.rb +31 -3
- data/lib/foreman_maintain/concerns/downstream.rb +2 -3
- data/lib/foreman_maintain/concerns/firewall/maintenance_mode.rb +31 -0
- data/lib/foreman_maintain/concerns/os_facts.rb +26 -2
- data/lib/foreman_maintain/concerns/system_helpers.rb +19 -17
- data/lib/foreman_maintain/package_manager/apt.rb +71 -0
- data/lib/foreman_maintain/package_manager/yum.rb +19 -11
- data/lib/foreman_maintain/package_manager.rb +6 -4
- data/lib/foreman_maintain/repository_manager/el.rb +15 -4
- data/lib/foreman_maintain/repository_manager.rb +1 -1
- data/lib/foreman_maintain/utils/service/systemd.rb +8 -13
- data/lib/foreman_maintain/version.rb +1 -1
- data/lib/foreman_maintain.rb +1 -0
- metadata +4 -7
- data/bin/passenger-recycler +0 -89
- data/config/passenger-recycler.yaml +0 -38
- data/definitions/procedures/passenger_recycler.rb +0 -14
- data/extras/passenger-recycler.cron +0 -3
@@ -4,13 +4,39 @@ module ForemanMaintain
|
|
4
4
|
def data_dir
|
5
5
|
if el7? && package_manager.installed?('rh-postgresql12-postgresql-server-syspaths')
|
6
6
|
'/var/opt/rh/rh-postgresql12/lib/pgsql/data/'
|
7
|
+
elsif debian_or_ubuntu?
|
8
|
+
deb_postgresql_data_dir
|
7
9
|
else
|
8
10
|
'/var/lib/pgsql/data/'
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
14
|
+
def deb_postgresql_data_dir
|
15
|
+
deb_postgresql_versions.map do |ver|
|
16
|
+
"/var/lib/postgresql/#{ver}/main/"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def deb_postgresql_versions
|
21
|
+
installed_pkgs = package_manager.list_installed_packages('${binary:Package}\n')
|
22
|
+
@deb_postgresql_versions ||= installed_pkgs.grep(/^postgresql-\d+$/).map do |name|
|
23
|
+
name.split('-').last
|
24
|
+
end
|
25
|
+
@deb_postgresql_versions
|
26
|
+
end
|
27
|
+
|
12
28
|
def postgresql_conf
|
13
|
-
"#{data_dir}/postgresql.conf"
|
29
|
+
return "#{data_dir}/postgresql.conf" if el?
|
30
|
+
|
31
|
+
deb_postgresql_config_dirs.map do |conf_dir|
|
32
|
+
"#{conf_dir}postgresql.conf"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def deb_postgresql_config_dirs
|
37
|
+
deb_postgresql_versions.map do |ver|
|
38
|
+
"/etc/postgresql/#{ver}/main/"
|
39
|
+
end
|
14
40
|
end
|
15
41
|
|
16
42
|
def restore_transform
|
@@ -89,11 +115,13 @@ module ForemanMaintain
|
|
89
115
|
|
90
116
|
def backup_local(backup_file, extra_tar_options = {})
|
91
117
|
dir = extra_tar_options.fetch(:data_dir, data_dir)
|
118
|
+
command = extra_tar_options.fetch(:command, 'create')
|
119
|
+
|
92
120
|
FileUtils.cd(dir) do
|
93
121
|
tar_options = {
|
94
122
|
:archive => backup_file,
|
95
|
-
:command =>
|
96
|
-
:transform => "s,^,#{
|
123
|
+
:command => command,
|
124
|
+
:transform => "s,^,#{dir[1..-1]},S",
|
97
125
|
:files => '*'
|
98
126
|
}.merge(extra_tar_options)
|
99
127
|
feature(:tar).run(tar_options)
|
@@ -66,7 +66,8 @@ module ForemanMaintain
|
|
66
66
|
server_version_full = "#{server_version.major}.#{server_version.minor}"
|
67
67
|
rh_repos.concat(product_specific_repos(server_version_full))
|
68
68
|
if server_version > version('6.3')
|
69
|
-
|
69
|
+
ansible_repo = ansible_repo(server_version)
|
70
|
+
rh_repos << ansible_repo if ansible_repo
|
70
71
|
end
|
71
72
|
|
72
73
|
rh_repos
|
@@ -83,8 +84,6 @@ module ForemanMaintain
|
|
83
84
|
|
84
85
|
if el7?
|
85
86
|
"rhel-#{el_major_version}-server-ansible-#{ansible_version}-rpms"
|
86
|
-
else
|
87
|
-
"ansible-#{ansible_version}-for-rhel-#{el_major_version}-x86_64-rpms"
|
88
87
|
end
|
89
88
|
end
|
90
89
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ForemanMaintain
|
2
|
+
module Concerns
|
3
|
+
module Firewall
|
4
|
+
module MaintenanceMode
|
5
|
+
def notify_and_ask_to_install_firewall_utility
|
6
|
+
puts 'Unable to find nftables or iptables!'
|
7
|
+
question, pkg = question_and_pkg_name
|
8
|
+
answer = ask_decision(question, actions_msg: 'y(yes), q(quit)')
|
9
|
+
if answer == :yes
|
10
|
+
packages_action(:install, pkg)
|
11
|
+
feature(:instance).firewall.enable_maintenance_mode
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def can_install_nft?
|
16
|
+
# The nftables is default from EL8 and Debian 10(Buster)
|
17
|
+
(el? && el_major_version >= 8) ||
|
18
|
+
(debian? && deb_major_version >= 10) ||
|
19
|
+
(ubuntu? && ubuntu_major_version.to_i >= 22)
|
20
|
+
end
|
21
|
+
|
22
|
+
def question_and_pkg_name
|
23
|
+
pkg_to_install = can_install_nft? ? 'nftables' : 'iptables'
|
24
|
+
question = "Do you want to install missing netfilter utility #{pkg_to_install}?"\
|
25
|
+
"\nand start maintenance mode?"
|
26
|
+
[question, [pkg_to_install]]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -46,12 +46,20 @@ module ForemanMaintain
|
|
46
46
|
facts.fetch('ID_LIKE', '').split
|
47
47
|
end
|
48
48
|
|
49
|
+
def os_name
|
50
|
+
facts.fetch('NAME')
|
51
|
+
end
|
52
|
+
|
49
53
|
def el?
|
50
54
|
File.exist?('/etc/redhat-release')
|
51
55
|
end
|
52
56
|
|
53
57
|
def debian?
|
54
|
-
|
58
|
+
os_id == 'debian'
|
59
|
+
end
|
60
|
+
|
61
|
+
def ubuntu?
|
62
|
+
os_id == 'ubuntu'
|
55
63
|
end
|
56
64
|
|
57
65
|
def el7?
|
@@ -63,7 +71,23 @@ module ForemanMaintain
|
|
63
71
|
end
|
64
72
|
|
65
73
|
def el_major_version
|
66
|
-
|
74
|
+
os_version_id.to_i if el?
|
75
|
+
end
|
76
|
+
|
77
|
+
def deb_major_version
|
78
|
+
os_version_id.to_i if debian?
|
79
|
+
end
|
80
|
+
|
81
|
+
def ubuntu_major_version
|
82
|
+
os_version_id if ubuntu?
|
83
|
+
end
|
84
|
+
|
85
|
+
def debian_or_ubuntu?
|
86
|
+
debian? || ubuntu?
|
87
|
+
end
|
88
|
+
|
89
|
+
def os_version
|
90
|
+
facts.fetch('VERSION')
|
67
91
|
end
|
68
92
|
end
|
69
93
|
end
|
@@ -100,12 +100,13 @@ module ForemanMaintain
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def packages_action(action, packages, options = {})
|
103
|
-
options.validate_options!(:assumeyes)
|
103
|
+
options.validate_options!(:assumeyes, :yum_options)
|
104
104
|
case action
|
105
105
|
when :install
|
106
106
|
package_manager.install(packages, :assumeyes => options[:assumeyes])
|
107
107
|
when :update
|
108
|
-
package_manager.update(packages, :assumeyes => options[:assumeyes]
|
108
|
+
package_manager.update(packages, :assumeyes => options[:assumeyes],
|
109
|
+
:yum_options => options[:yum_options])
|
109
110
|
when :remove
|
110
111
|
package_manager.remove(packages, :assumeyes => options[:assumeyes])
|
111
112
|
else
|
@@ -114,8 +115,13 @@ module ForemanMaintain
|
|
114
115
|
end
|
115
116
|
|
116
117
|
def package_version(name)
|
117
|
-
|
118
|
-
|
118
|
+
ver = if el?
|
119
|
+
'%{VERSION}'
|
120
|
+
elsif debian_or_ubuntu?
|
121
|
+
'${VERSION}'
|
122
|
+
end
|
123
|
+
pkg = package_manager.find_installed_package(name, ver)
|
124
|
+
version(pkg) unless pkg.nil?
|
119
125
|
end
|
120
126
|
|
121
127
|
def parse_csv(data)
|
@@ -132,18 +138,14 @@ module ForemanMaintain
|
|
132
138
|
nil
|
133
139
|
end
|
134
140
|
|
135
|
-
def rpm_version(name)
|
136
|
-
rpm_version = execute(%(rpm -q '#{name}' --queryformat="%{VERSION}"))
|
137
|
-
if $CHILD_STATUS.success?
|
138
|
-
version(rpm_version)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
141
|
def shellescape(string)
|
143
142
|
Shellwords.escape(string)
|
144
143
|
end
|
145
144
|
|
146
145
|
def version(value)
|
146
|
+
# packages versions, especially on Debian, sometimes include a + or a ~,
|
147
|
+
# but Gem::Version can't handle that.
|
148
|
+
value.gsub!(/[+~]/, '-')
|
147
149
|
Version.new(value)
|
148
150
|
end
|
149
151
|
|
@@ -190,7 +192,7 @@ module ForemanMaintain
|
|
190
192
|
end
|
191
193
|
|
192
194
|
def ruby_prefix(scl = true)
|
193
|
-
if
|
195
|
+
if debian_or_ubuntu?
|
194
196
|
'ruby-'
|
195
197
|
elsif el7? && scl
|
196
198
|
'tfm-rubygem-'
|
@@ -200,12 +202,12 @@ module ForemanMaintain
|
|
200
202
|
end
|
201
203
|
|
202
204
|
def foreman_plugin_name(plugin)
|
203
|
-
plugin = plugin.tr('_', '-') if
|
205
|
+
plugin = plugin.tr('_', '-') if debian_or_ubuntu?
|
204
206
|
ruby_prefix + plugin
|
205
207
|
end
|
206
208
|
|
207
209
|
def proxy_plugin_name(plugin)
|
208
|
-
if
|
210
|
+
if debian_or_ubuntu?
|
209
211
|
plugin = plugin.tr('_', '-')
|
210
212
|
proxy_plugin_prefix = 'smart-proxy-'
|
211
213
|
else
|
@@ -216,12 +218,12 @@ module ForemanMaintain
|
|
216
218
|
end
|
217
219
|
|
218
220
|
def hammer_plugin_name(plugin)
|
219
|
-
plugin = plugin.tr('_', '-') if
|
220
|
-
[hammer_package, plugin].join(
|
221
|
+
plugin = plugin.tr('_', '-') if debian_or_ubuntu?
|
222
|
+
[hammer_package, plugin].join(debian_or_ubuntu? ? '-' : '_')
|
221
223
|
end
|
222
224
|
|
223
225
|
def hammer_package
|
224
|
-
hammer_prefix = if
|
226
|
+
hammer_prefix = if debian_or_ubuntu?
|
225
227
|
'hammer-cli'
|
226
228
|
else
|
227
229
|
'hammer_cli'
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module ForemanMaintain::PackageManager
|
2
|
+
class Apt < Base
|
3
|
+
def installed?(packages)
|
4
|
+
packages_list = [packages].flatten(1).map { |pkg| "'#{pkg}'" }.join(' ')
|
5
|
+
status, output = sys.execute_with_status(%(dpkg --status #{packages_list}))
|
6
|
+
return false if status != 0
|
7
|
+
|
8
|
+
status_of_pkg = output.split("\n").grep(/^Status:/).first
|
9
|
+
status_of_pkg.include?('installed')
|
10
|
+
end
|
11
|
+
|
12
|
+
def install(packages, assumeyes: false)
|
13
|
+
apt_action('install', packages, :assumeyes => assumeyes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def remove(packages, assumeyes: false)
|
17
|
+
apt_action('remove', packages, :assumeyes => assumeyes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(packages = [], assumeyes: false)
|
21
|
+
action = packages.any? ? '--only-upgrade install' : 'upgrade'
|
22
|
+
apt_action(action, packages, :assumeyes => assumeyes)
|
23
|
+
end
|
24
|
+
|
25
|
+
def clean_cache(assumeyes: false)
|
26
|
+
apt_action('clean', :assumeyes => assumeyes)
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_installed_package(name, queryfm = '')
|
30
|
+
return unless installed?(name)
|
31
|
+
|
32
|
+
dpkg_cmd = "dpkg-query --show #{name}"
|
33
|
+
unless queryfm.empty?
|
34
|
+
dpkg_cmd = "dpkg-query --showformat='#{queryfm}' --show #{name}"
|
35
|
+
end
|
36
|
+
_, result = sys.execute_with_status(dpkg_cmd)
|
37
|
+
result
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_update(packages: nil, with_status: false)
|
41
|
+
apt_action('upgrade --dry-run', packages, :with_status => with_status)
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_installed_packages(queryfm = '${binary:Package}-${VERSION}\n')
|
45
|
+
# The queryfm should only include valid tag(s) as per `dpkg-query` man page.
|
46
|
+
# If any special formatting is required with querytag then it should be provided with tag i.e,
|
47
|
+
# querytag = "--%{VERSION}"
|
48
|
+
# The queryfm string must end with '\n'
|
49
|
+
sys.execute!("dpkg-query --showformat='#{queryfm}' -W").split("\n")
|
50
|
+
end
|
51
|
+
|
52
|
+
def version_locking_supported?
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
def apt_action(action, packages, with_status: false, assumeyes: false, valid_exit_statuses: [0])
|
57
|
+
apt_options = []
|
58
|
+
packages = [packages].flatten(1)
|
59
|
+
apt_options << '-y' if assumeyes
|
60
|
+
apt_options_s = apt_options.empty? ? '' : ' ' + apt_options.join(' ')
|
61
|
+
packages_s = packages.empty? ? '' : ' ' + packages.join(' ')
|
62
|
+
if with_status
|
63
|
+
sys.execute_with_status("apt-get#{apt_options_s} #{action}#{packages_s}",
|
64
|
+
:interactive => !assumeyes)
|
65
|
+
else
|
66
|
+
sys.execute!("apt-get#{apt_options_s} #{action}#{packages_s}",
|
67
|
+
:interactive => !assumeyes, :valid_exit_statuses => valid_exit_statuses)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -36,8 +36,12 @@ module ForemanMaintain::PackageManager
|
|
36
36
|
sys.execute?(%(rpm -q #{packages_list}))
|
37
37
|
end
|
38
38
|
|
39
|
-
def find_installed_package(name)
|
40
|
-
|
39
|
+
def find_installed_package(name, queryformat = '')
|
40
|
+
rpm_cmd = "rpm -q '#{name}'"
|
41
|
+
unless queryformat.empty?
|
42
|
+
rpm_cmd += " --qf '#{queryformat}'"
|
43
|
+
end
|
44
|
+
status, result = sys.execute_with_status(rpm_cmd)
|
41
45
|
if status == 0
|
42
46
|
result
|
43
47
|
end
|
@@ -55,8 +59,8 @@ module ForemanMaintain::PackageManager
|
|
55
59
|
yum_action('remove', packages, :assumeyes => assumeyes)
|
56
60
|
end
|
57
61
|
|
58
|
-
def update(packages = [], assumeyes: false)
|
59
|
-
yum_action('update', packages, :assumeyes => assumeyes)
|
62
|
+
def update(packages = [], assumeyes: false, yum_options: [])
|
63
|
+
yum_action('update', packages, :assumeyes => assumeyes, :yum_options => yum_options)
|
60
64
|
end
|
61
65
|
|
62
66
|
def clean_cache(assumeyes: false)
|
@@ -78,12 +82,12 @@ module ForemanMaintain::PackageManager
|
|
78
82
|
sys.execute(find_cmd).split("\n")
|
79
83
|
end
|
80
84
|
|
81
|
-
def list_installed_packages(
|
82
|
-
# The
|
85
|
+
def list_installed_packages(queryformat = '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n')
|
86
|
+
# The queryformat should only include valid tag(s) as per `rpm --querytags` list.
|
83
87
|
# If any special formatting is required with querytag then it should be provided with tag i.e,
|
84
|
-
#
|
85
|
-
# The
|
86
|
-
sys.execute!("rpm -qa --qf '#{
|
88
|
+
# "--%{VENDOR}"
|
89
|
+
# The queryformat string must end with '\n'
|
90
|
+
sys.execute!("rpm -qa --qf '#{queryformat}'").split("\n")
|
87
91
|
end
|
88
92
|
|
89
93
|
private
|
@@ -116,8 +120,12 @@ module ForemanMaintain::PackageManager
|
|
116
120
|
File.open(protector_config_file, 'w') { |file| file.puts config }
|
117
121
|
end
|
118
122
|
|
119
|
-
|
120
|
-
|
123
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
124
|
+
def yum_action(action, packages, options)
|
125
|
+
with_status = options.fetch(:with_status, false)
|
126
|
+
assumeyes = options.fetch(:assumeyes, false)
|
127
|
+
valid_exit_statuses = options.fetch(:valid_exit_statuses, [0])
|
128
|
+
yum_options = options.fetch(:yum_options, [])
|
121
129
|
packages = [packages].flatten(1)
|
122
130
|
yum_options << '-y' if assumeyes
|
123
131
|
yum_options << '--disableplugin=foreman-protector'
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'foreman_maintain/package_manager/base'
|
2
2
|
require 'foreman_maintain/package_manager/yum'
|
3
3
|
require 'foreman_maintain/package_manager/dnf'
|
4
|
+
require 'foreman_maintain/package_manager/apt'
|
4
5
|
|
5
6
|
module ForemanMaintain
|
6
7
|
def self.package_manager
|
7
|
-
@package_manager ||=
|
8
|
-
when 'dnf'
|
9
|
-
ForemanMaintain::PackageManager::Dnf.new
|
10
|
-
when 'yum'
|
8
|
+
@package_manager ||= if el7?
|
11
9
|
ForemanMaintain::PackageManager::Yum.new
|
10
|
+
elsif el?
|
11
|
+
ForemanMaintain::PackageManager::Dnf.new
|
12
|
+
elsif debian_or_ubuntu?
|
13
|
+
ForemanMaintain::PackageManager::Apt.new
|
12
14
|
else
|
13
15
|
raise 'No supported package manager was found'
|
14
16
|
end
|
@@ -76,10 +76,21 @@ module ForemanMaintain::RepositoryManager
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def hash_of_repoids_urls(repos, regex)
|
79
|
-
Hash[*repos.split("\n").grep(regex).map do |entry|
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
ids_urls = Hash[*repos.split("\n").grep(regex).map do |entry|
|
80
|
+
entry.split(':', 2).last.strip
|
81
|
+
end]
|
82
|
+
|
83
|
+
# The EL7 yum repolist output includes extra info in the output,
|
84
|
+
# as example
|
85
|
+
# rhel-7-server-rpms/7Server/x86_64
|
86
|
+
# rhel-server-rhscl-7-rpms/7Server/x86_64
|
87
|
+
# This trims anything after first '/' to get correct repo label
|
88
|
+
trimmed_hash = {}
|
89
|
+
ids_urls.each do |id, url|
|
90
|
+
trimmed_id = id.split('/').first
|
91
|
+
trimmed_hash[trimmed_id] = url
|
92
|
+
end
|
93
|
+
trimmed_hash
|
83
94
|
end
|
84
95
|
end
|
85
96
|
end
|
@@ -8,21 +8,16 @@ module ForemanMaintain::Utils
|
|
8
8
|
@instance_parent_unit = options.fetch(:instance_parent_unit, nil)
|
9
9
|
end
|
10
10
|
|
11
|
-
def command(action
|
12
|
-
do_wait = options.fetch(:wait, true) # wait for service to start
|
11
|
+
def command(action)
|
13
12
|
all = @options.fetch(:all, false)
|
14
13
|
skip_enablement = @options.fetch(:skip_enablement, false)
|
15
14
|
if skip_enablement && %w[enable disable].include?(action)
|
16
15
|
return skip_enablement_message(action, @name)
|
17
16
|
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
cmd = "systemctl #{action} #{@name}"
|
23
|
-
cmd += ' --all' if all
|
24
|
-
cmd
|
25
|
-
end
|
18
|
+
cmd = "systemctl #{action} #{@name}"
|
19
|
+
cmd += ' --all' if all
|
20
|
+
cmd
|
26
21
|
end
|
27
22
|
|
28
23
|
def status
|
@@ -38,11 +33,11 @@ module ForemanMaintain::Utils
|
|
38
33
|
end
|
39
34
|
|
40
35
|
def enable
|
41
|
-
execute('enable'
|
36
|
+
execute('enable')
|
42
37
|
end
|
43
38
|
|
44
39
|
def disable
|
45
|
-
execute('disable'
|
40
|
+
execute('disable')
|
46
41
|
end
|
47
42
|
|
48
43
|
def running?
|
@@ -66,8 +61,8 @@ module ForemanMaintain::Utils
|
|
66
61
|
|
67
62
|
private
|
68
63
|
|
69
|
-
def execute(action
|
70
|
-
@sys.execute_with_status(command(action
|
64
|
+
def execute(action)
|
65
|
+
@sys.execute_with_status(command(action))
|
71
66
|
end
|
72
67
|
|
73
68
|
def service_enabled_status
|
data/lib/foreman_maintain.rb
CHANGED
@@ -26,6 +26,7 @@ module ForemanMaintain
|
|
26
26
|
require 'foreman_maintain/concerns/pulp_common'
|
27
27
|
require 'foreman_maintain/concerns/firewall/iptables_maintenance_mode'
|
28
28
|
require 'foreman_maintain/concerns/firewall/nftables_maintenance_mode'
|
29
|
+
require 'foreman_maintain/concerns/firewall/maintenance_mode'
|
29
30
|
require 'foreman_maintain/top_level_modules'
|
30
31
|
require 'foreman_maintain/yaml_storage'
|
31
32
|
require 'foreman_maintain/config'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_maintain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clamp
|
@@ -113,7 +113,6 @@ description: Provides various features that helps keeping the Foreman/Satellite
|
|
113
113
|
email: inecas@redhat.com
|
114
114
|
executables:
|
115
115
|
- foreman-maintain
|
116
|
-
- passenger-recycler
|
117
116
|
- foreman-maintain-complete
|
118
117
|
- foreman-maintain-rotate-tar
|
119
118
|
extensions: []
|
@@ -126,12 +125,10 @@ files:
|
|
126
125
|
- bin/foreman-maintain
|
127
126
|
- bin/foreman-maintain-complete
|
128
127
|
- bin/foreman-maintain-rotate-tar
|
129
|
-
- bin/passenger-recycler
|
130
128
|
- config/foreman-maintain.completion
|
131
129
|
- config/foreman_maintain.yml.example
|
132
130
|
- config/foreman_maintain.yml.packaging
|
133
131
|
- config/hammer.yml.example
|
134
|
-
- config/passenger-recycler.yaml
|
135
132
|
- definitions/checks/backup/certs_tar_exist.rb
|
136
133
|
- definitions/checks/backup/directory_ready.rb
|
137
134
|
- definitions/checks/candlepin/db_up.rb
|
@@ -281,7 +278,6 @@ files:
|
|
281
278
|
- definitions/procedures/packages/unlock_versions.rb
|
282
279
|
- definitions/procedures/packages/update.rb
|
283
280
|
- definitions/procedures/packages/update_all_confirmation.rb
|
284
|
-
- definitions/procedures/passenger_recycler.rb
|
285
281
|
- definitions/procedures/prep_6_10_upgrade.rb
|
286
282
|
- definitions/procedures/pulp/cleanup_old_metadata_files.rb
|
287
283
|
- definitions/procedures/pulp/migrate.rb
|
@@ -365,7 +361,6 @@ files:
|
|
365
361
|
- extras/foreman_protector/foreman-protector.conf
|
366
362
|
- extras/foreman_protector/foreman-protector.whitelist
|
367
363
|
- extras/foreman_protector/yum/foreman-protector.py
|
368
|
-
- extras/passenger-recycler.cron
|
369
364
|
- lib/foreman_maintain.rb
|
370
365
|
- lib/foreman_maintain/check.rb
|
371
366
|
- lib/foreman_maintain/cli.rb
|
@@ -393,6 +388,7 @@ files:
|
|
393
388
|
- lib/foreman_maintain/concerns/downstream.rb
|
394
389
|
- lib/foreman_maintain/concerns/finders.rb
|
395
390
|
- lib/foreman_maintain/concerns/firewall/iptables_maintenance_mode.rb
|
391
|
+
- lib/foreman_maintain/concerns/firewall/maintenance_mode.rb
|
396
392
|
- lib/foreman_maintain/concerns/firewall/nftables_maintenance_mode.rb
|
397
393
|
- lib/foreman_maintain/concerns/hammer.rb
|
398
394
|
- lib/foreman_maintain/concerns/logger.rb
|
@@ -414,6 +410,7 @@ files:
|
|
414
410
|
- lib/foreman_maintain/executable.rb
|
415
411
|
- lib/foreman_maintain/feature.rb
|
416
412
|
- lib/foreman_maintain/package_manager.rb
|
413
|
+
- lib/foreman_maintain/package_manager/apt.rb
|
417
414
|
- lib/foreman_maintain/package_manager/base.rb
|
418
415
|
- lib/foreman_maintain/package_manager/dnf.rb
|
419
416
|
- lib/foreman_maintain/package_manager/yum.rb
|
data/bin/passenger-recycler
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# Trivial Passenger memory monitor and recycler. See the configuration file
|
4
|
-
# /etc/passenger-recycler.yaml for options. Execute via SCL.
|
5
|
-
#
|
6
|
-
require 'yaml'
|
7
|
-
|
8
|
-
CONFIG = {}.freeze
|
9
|
-
CONFIG_FILE = '/etc/passenger-recycler.yaml'.freeze
|
10
|
-
CONFIG = YAML.load_file(CONFIG_FILE) if File.readable?(CONFIG_FILE)
|
11
|
-
exit 0 unless CONFIG[:ENABLED]
|
12
|
-
|
13
|
-
def running?(pid)
|
14
|
-
Process.getpgid(pid) != -1
|
15
|
-
rescue Errno::ESRCH
|
16
|
-
false
|
17
|
-
end
|
18
|
-
|
19
|
-
def debug(msg)
|
20
|
-
puts(msg) if CONFIG[:DEBUG]
|
21
|
-
end
|
22
|
-
|
23
|
-
def verbose(msg)
|
24
|
-
puts(msg) if CONFIG[:VERBOSE]
|
25
|
-
end
|
26
|
-
|
27
|
-
def kill(pid)
|
28
|
-
return unless running?(pid) && CONFIG[:KILL_BUSY]
|
29
|
-
verbose "Process #{pid} is still running, sending SIGKILL"
|
30
|
-
Process.kill 'KILL', pid
|
31
|
-
sleep 5
|
32
|
-
end
|
33
|
-
|
34
|
-
def process_status?(pid)
|
35
|
-
if running?(pid)
|
36
|
-
verbose "Process #{pid} still terminating, moving on..."
|
37
|
-
else
|
38
|
-
verbose "Process successfully #{pid} terminated"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def show_passenger_status(status_messages)
|
43
|
-
status_messages.each { |msg| verbose msg }
|
44
|
-
end
|
45
|
-
|
46
|
-
require 'phusion_passenger'
|
47
|
-
PhusionPassenger.locate_directories
|
48
|
-
require 'phusion_passenger/platform_info'
|
49
|
-
require 'phusion_passenger/platform_info/ruby'
|
50
|
-
require 'phusion_passenger/admin_tools/memory_stats'
|
51
|
-
stats = PhusionPassenger::AdminTools::MemoryStats.new
|
52
|
-
killed = 0
|
53
|
-
|
54
|
-
def get_process_start(pid)
|
55
|
-
`ps -p#{pid} -o start=`.strip
|
56
|
-
rescue StandardError => e
|
57
|
-
verbose "Error: #{e.message} \nReturning '?'"
|
58
|
-
'?'
|
59
|
-
end
|
60
|
-
|
61
|
-
def get_rss_info(process)
|
62
|
-
get_pid_mem_kb = process.private_dirty_rss || process.rss
|
63
|
-
get_pid_mem_mb = format('%.0f', get_pid_mem_kb / 1024)
|
64
|
-
[get_pid_mem_kb, get_pid_mem_mb]
|
65
|
-
end
|
66
|
-
|
67
|
-
stats.passenger_processes.each do |p|
|
68
|
-
pid = p.pid.to_i
|
69
|
-
started = get_process_start(pid)
|
70
|
-
get_pid_mem_kb, get_pid_mem_mb = get_rss_info(p)
|
71
|
-
debug "Checking #{pid} with RSS of #{get_pid_mem_kb}"
|
72
|
-
next unless get_pid_mem_kb > CONFIG[:MAX_PRIV_RSS_MEMORY]
|
73
|
-
status_ps = `ps -p#{pid} -u`
|
74
|
-
status_all = `passenger-status 2> /dev/null`
|
75
|
-
status_backtraces = `passenger-status --show=backtraces 2>/dev/null`
|
76
|
-
verbose("Terminating #{pid} (started #{started}) with private RSS size of #{get_pid_mem_mb} MB")
|
77
|
-
begin
|
78
|
-
Process.kill 'SIGUSR1', pid
|
79
|
-
sleep CONFIG[:GRACEFUL_SHUTDOWN_SLEEP]
|
80
|
-
kill(pid)
|
81
|
-
process_status?(pid)
|
82
|
-
show_passenger_status([status_ps, status_all, status_backtraces]) if CONFIG[:SEND_STATUS]
|
83
|
-
killed += 1
|
84
|
-
exit(1) if killed >= CONFIG[:MAX_TERMINATION]
|
85
|
-
rescue Errno::ESRCH
|
86
|
-
puts "#{Process.pid}: #{pid} is NOT running"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
exit 0
|