forked from Katello/katello-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
30-upgrade.rb
174 lines (139 loc) · 5.59 KB
/
30-upgrade.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
require 'fileutils'
STEP_DIRECTORY = '/etc/foreman-installer/applied_hooks/pre/'
SSL_BUILD_DIR = param('certs', 'ssl_build_dir').value
def stop_services
Kafo::Helpers.execute('katello-service stop --exclude mongod,postgresql')
end
def start_databases
Kafo::Helpers.execute('katello-service start --only mongod,postgresql')
end
def start_httpd
Kafo::Helpers.execute('katello-service start --only httpd')
end
def start_qpidd
Kafo::Helpers.execute('katello-service start --only qpidd,qdrouterd')
end
def start_pulp
Kafo::Helpers.execute('katello-service start --only pulp_workers,pulp_resource_manager,pulp_celerybeat')
end
def update_http_conf
Kafo::Helpers.execute("grep -F -q 'Include \"/etc/httpd/conf.modules.d/*.conf\"' /etc/httpd/conf/httpd.conf || \
echo -e '<IfVersion >= 2.4> \n Include \"/etc/httpd/conf.modules.d/*.conf\"\n</IfVersion>' \
>> /etc/httpd/conf/httpd.conf")
end
def migrate_candlepin
Kafo::Helpers.execute("/usr/share/candlepin/cpdb --update --password #{Kafo::Helpers.read_cache_data('candlepin_db_password')}")
end
def start_tomcat
Kafo::Helpers.execute('katello-service start --only tomcat,tomcat6')
end
def remove_gutterball
gbpresent = `runuser - postgres -c "psql -l | grep gutterball | wc -l"`.chomp.to_i
if gbpresent > 0
Kafo::Helpers.execute('runuser - postgres -c "dropdb gutterball"')
else
logger.info 'Gutterball is already removed, skipping'
end
end
def migrate_pulp
# Fix pid if neccessary
if Kafo::Helpers.execute("grep -qe '7.[[:digit:]]' /etc/redhat-release")
Kafo::Helpers.execute("sed -i -e 's?/var/run/mongodb/mongodb.pid?/var/run/mongodb/mongod.pid?g' /etc/mongod.conf")
end
# Start mongo if not running
unless Kafo::Helpers.execute('pgrep mongod')
Kafo::Helpers.execute('service-wait mongod start')
end
Kafo::Helpers.execute('su - apache -s /bin/bash -c pulp-manage-db')
end
def migrate_foreman
Kafo::Helpers.execute(['foreman-rake -- config -k use_pulp_oauth -v true >/dev/null',
'foreman-rake db:migrate',
'foreman-rake -- config -k use_pulp_oauth -v false >/dev/null'])
end
def remove_nodes_importers
Kafo::Helpers.execute("mongo pulp_database --eval 'db.repo_importers.remove({'importer_type_id': \"nodes_http_importer\"});'")
end
def remove_nodes_distributors
Kafo::Helpers.execute("mongo pulp_database --eval 'db.repo_distributors.remove({'distributor_type_id': \"nodes_http_distributor\"});'")
end
def fix_katello_settings_file
settings_file = '/etc/foreman/plugins/katello.yaml'
settings = JSON.parse(JSON.dump(YAML.load_file(settings_file)), :symbolize_names => true)
return true unless settings.key?(:common)
settings = {:katello => settings[:common]}
File.open(settings_file, 'w') do |file|
file.write(settings.to_yaml)
end
end
def mark_qpid_cert_for_update
hostname = param('certs', 'node_fqdn').value
all_cert_names = Dir.glob(File.join(SSL_BUILD_DIR, hostname, '*.noarch.rpm')).map do |rpm|
File.basename(rpm).sub(/-1\.0-\d+\.noarch\.rpm/, '')
end.uniq
if (qpid_cert = all_cert_names.find { |cert| cert =~ /-qpid-broker$/ })
path = File.join(*[SSL_BUILD_DIR, hostname, qpid_cert].compact)
Kafo::Helpers.log_and_say :info, "Marking certificate #{path} for update"
FileUtils.touch("#{path}.update")
else
Kafo::Helpers.log_and_say :debug, "No existing broker cert found; skipping update"
end
end
def upgrade_step(step, options = {})
noop = app_value(:noop) ? ' (noop)' : ''
long_running = options[:long_running] ? ' (this may take a while) ' : ''
run_always = options.fetch(:run_always, false)
if run_always || app_value(:force_upgrade_steps) || !step_ran?(step)
Kafo::Helpers.log_and_say :info, "Upgrade Step: #{step}#{long_running}#{noop}..."
unless app_value(:noop)
status = send(step)
fail_and_exit "Upgrade step #{step} failed. Check logs for more information." unless status
touch_step(step)
end
end
end
def touch_step(step)
FileUtils.mkpath(STEP_DIRECTORY) unless Dir.exists?(STEP_DIRECTORY)
FileUtils.touch(step_path(step))
end
def step_ran?(step)
File.exists?(step_path(step))
end
def step_path(step)
File.join(STEP_DIRECTORY, step.to_s)
end
def fail_and_exit(message)
Kafo::Helpers.log_and_say :error, message
kafo.class.exit 1
end
if app_value(:upgrade)
if app_value(:upgrade_puppet)
fail_and_exit 'Concurrent use of --upgrade and --upgrade-puppet is not supported. '\
'Please run --upgrade first, then --upgrade-puppet.'
end
Kafo::Helpers.log_and_say :info, 'Upgrading...'
katello = Kafo::Helpers.module_enabled?(@kafo, 'katello')
foreman_proxy_content = @kafo.param('foreman_proxy_plugin_pulp', 'pulpnode_enabled').value
upgrade_step :stop_services, :run_always => true
upgrade_step :start_databases, :run_always => true
upgrade_step :update_http_conf, :run_always => true
if katello || foreman_proxy_content
upgrade_step :migrate_pulp, :run_always => true
upgrade_step :start_httpd, :run_always => true
upgrade_step :start_qpidd, :run_always => true
upgrade_step :start_pulp, :run_always => true
end
if foreman_proxy_content
upgrade_step :remove_nodes_importers
end
if katello
upgrade_step :mark_qpid_cert_for_update
upgrade_step :migrate_candlepin, :run_always => true
upgrade_step :remove_gutterball
upgrade_step :start_tomcat, :run_always => true
upgrade_step :fix_katello_settings_file
upgrade_step :migrate_foreman, :run_always => true
upgrade_step :remove_nodes_distributors
end
Kafo::Helpers.log_and_say :info, 'Upgrade Step: Running installer...'
end