Skip to content

Commit ddb6b36

Browse files
committed
Fixes #37686 - Stop puppetserver if java is too old
When upgrading from puppetserver 7 to puppetserver 8 it'll typically be configured with /usr/bin/java and that usually points to Java 8. Puppetserver 8 has started to require Java 11, so upgrading fails. By properly stopping the service before running Puppet we know for sure that it can be started safely again. It also helps free up CPU from the constant restart loop, which reduces the slowdown.
1 parent 8e00591 commit ddb6b36

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

hooks/boot/04-services.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def stop_services(services = ALL_POSSIBLE_SERVICES)
2424
raise "Can't stop all services" if services.empty?
2525

2626
logger.debug('Getting running services')
27-
stdout_str, stderr_str, status = Open3.capture3('systemctl', 'list-units', '--no-legend', '--type=service,socket', '--state=running', *services)
27+
stdout_str, stderr_str, status = Open3.capture3('systemctl', 'list-units', '--no-legend', '--type=service,socket', '--state=activating,running', *services)
2828
fail_and_exit("Failed to get running services: #{stderr_str}", status.exitstatus) unless status.success?
2929
running = stdout_str.lines.map { |line| line.split.first }
3030
logger.debug("Found running services #{running.inspect}")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# With Puppetserver 8 the minimum java version has been increased to Java 11
2+
# If the user is upgrading from Puppet 7 to Puppet 8 then /usr/bin/java may
3+
# point to Java 8, which is what Puppetserver uses by default. The installer
4+
# will explicitly configure Java 17, but puppetserver.service can end up in a
5+
# restart loop where puppet can't properly restart the service.
6+
#
7+
# This hook detects Java 8 and Puppetserver 8 and explicitly stops the service.
8+
# The installer should then reconfigure it and start it again.
9+
#
10+
# See https://github.com/theforeman/puppet-puppet/pull/910 which is currently
11+
# only implemented for Red Hat based systems.
12+
sysconfig_file = '/etc/sysconfig/puppetserver'
13+
if File.exist?(sysconfig_file)
14+
puppetserver_stdout_stderr, _status = execute_command('puppetserver --version', false, true)
15+
puppetserver_stdout_stderr&.match(/puppetserver version: (?<version>\d+)\.\d+\.\d+/) do |puppetserver_match|
16+
logger.debug("Found Puppetserver #{puppetserver_match[:version]}")
17+
if puppetserver_match[:version] == '8'
18+
java_stdout_stderr, _status = execute_command("source #{sysconfig_file} ; $JAVA_BIN -version", false, true)
19+
java_stdout_stderr&.match(/version "\d+\.(?<version>\d+)\.\d+/) do |java_match|
20+
if java_match[:version] && java_match[:version].to_i < 11
21+
logger.info "Detected Java #{java_match[:version]} which is too old for Puppetserver #{puppetserver_match[:version]}"
22+
if app_value(:noop)
23+
logger.debug 'Would stop puppetserver.service'
24+
else
25+
stop_services(['puppetserver.service'])
26+
end
27+
end
28+
end
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)