Skip to content

Commit

Permalink
Merge pull request #361 from caseywilliams/MODULES-8443/puppet6-foss-…
Browse files Browse the repository at this point in the history
…mco-restarts

(MODULES-8443) Don't restart mco for FOSS puppet6 upgrades
  • Loading branch information
Sean P McDonald authored Jan 15, 2019
2 parents 3d48279 + 4fcb523 commit eff9218
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 29 deletions.
13 changes: 6 additions & 7 deletions files/solaris_start_puppet.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash

puppet_pid=$1
shift
service_names=$*

while $(kill -0 ${puppet_pid:?}); do
sleep 5
done

function start_service() {
service="${1:?}"
/opt/puppetlabs/bin/puppet resource service "${service:?}" ensure=running enable=true
}

start_service puppet
start_service mcollective
for service_name in $service_names; do
/opt/puppetlabs/bin/puppet resource service "${service_name:?}" ensure=running enable=true
done
8 changes: 5 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,16 @@
contain '::puppet_agent::prepare'
contain '::puppet_agent::install'

# On windows, our MSI handles the services
# On PE AIO nodes, PE Agent nodegroup is managing the services
# Service management:
# - Under Puppet Enterprise, the agent nodegroup is managed by PE, and we don't need to manage services here.
# - On Windows, services are handled by the puppet-agent MSI packages themselves.
# ...but outside of PE, on other platforms, we must make sure the services are restarted. We do that with the
# ::puppet_agent::service class. Make sure it's applied after the install process finishes if needed:
if $::osfamily != 'windows' and (!$is_pe or versioncmp($::clientversion, '4.0.0') < 0) {
class { '::puppet_agent::service':
require => Class['::puppet_agent::install'],
}
contain '::puppet_agent::service'
}

}
}
1 change: 1 addition & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# The following are expected to be available in the solaris_install.sh.erb template:
$adminfile = '/opt/puppetlabs/packages/solaris-noask'
$sourcefile = "/opt/puppetlabs/packages/${_unzipped_package_name}"
$service_names = $puppet_agent::service_names

# Puppet prior to 5.0 would not use a separate process contract when forking from the Puppet
# service. That resulted in service-initiated upgrades failing because trying to remove or
Expand Down
21 changes: 12 additions & 9 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
fail('The puppet_agent class requires stringify_facts to be disabled')
}

# Which services should be started after the upgrade process?
if ($::osfamily == 'Solaris' and $::operatingsystemmajrelease == '11') {
# Solaris 11 is a special case; it uses a custom script.
$service_names = []
} elsif (versioncmp("${::clientversion}", '5.99.0') < 0) { # (5.99.z indicates pre-release puppet6)
# Earlier versions Puppet (4 and 5) rely on mcollective:
$service_names = ['puppet', 'mcollective']
} else {
# Puppet 6+ only needs to manage the puppet service:
$service_names = ['puppet']
}

# The `is_pe` fact currently works by echoing out the puppet version
# and greping for "puppet enterprise". With Puppet 4 and PE 2015.2, there
# is no longer a "PE Puppet", and so that fact will no longer work.
Expand All @@ -32,13 +44,6 @@

case $::osfamily {
'RedHat', 'Debian', 'Suse', 'Solaris', 'Darwin', 'AIX': {
if !($::osfamily == 'Solaris' and $::operatingsystemmajrelease == '11') {
$service_names = ['puppet', 'mcollective']
}
else {
$service_names = []
}

$local_puppet_dir = '/opt/puppetlabs'
$local_packages_dir = "${local_puppet_dir}/packages"

Expand All @@ -59,8 +64,6 @@
$group = 0
}
'windows' : {
$service_names = ['puppet', 'mcollective']

$local_puppet_dir = windows_native_path("${::puppet_agent_appdata}/Puppetlabs")
$local_packages_dir = windows_native_path("${local_puppet_dir}/packages")

Expand Down
7 changes: 4 additions & 3 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# == Class puppet_agent::service
#
# This class is meant to be called from puppet_agent.
# It ensures services is running.
# It ensures that managed services are running.
#
class puppet_agent::service {
assert_private()
Expand All @@ -12,21 +12,22 @@
((versioncmp("${::clientversion}", '4.0.0') < 0) or $puppet_agent::aio_upgrade_required) {
# Only use script if we just performed an upgrade.
$_logfile = "${::env_temp_variable}/solaris_start_puppet.log"
# We'll need to pass the names of the services to start to the script
$_service_names_arg = join($::puppet_agent::service_names, ' ')
notice ("Puppet service start log file at ${_logfile}")
file { "${::env_temp_variable}/solaris_start_puppet.sh":
ensure => file,
source => 'puppet:///modules/puppet_agent/solaris_start_puppet.sh',
mode => '0755',
}
-> exec { 'solaris_start_puppet.sh':
command => "${::env_temp_variable}/solaris_start_puppet.sh ${::puppet_agent_pid} 2>&1 > ${_logfile} &",
command => "${::env_temp_variable}/solaris_start_puppet.sh ${::puppet_agent_pid} ${_service_names_arg} 2>&1 > ${_logfile} &",
path => '/usr/bin:/bin:/usr/sbin',
}
file { ['/var/opt/lib', '/var/opt/lib/pe-puppet', '/var/opt/lib/pe-puppet/state']:
ensure => directory,
}
} else {

$::puppet_agent::service_names.each |$service| {
service { $service:
ensure => running,
Expand Down
2 changes: 2 additions & 0 deletions manifests/windows/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
) {
assert_private()

$service_names = $::puppet_agent::service_names

if $::puppet_agent::is_pe {
$_agent_version = $puppet_agent::params::master_agent_version
$_pe_server_version = pe_build_version()
Expand Down
7 changes: 5 additions & 2 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,16 @@ def global_facts(facts, os)
end
end

# Windows platform does not use Service resources
# Windows platform does not use Service resources; their services
# are managed by the MSI installer.
unless facts[:osfamily] == 'windows'
if params[:service_names].nil? &&
!(facts[:osfamily] == 'Solaris' && facts[:operatingsystemmajrelease] == '11') &&
os !~ /sles/
it { is_expected.to contain_service('puppet') }
it { is_expected.to contain_service('mcollective') }
if Puppet.version < "5.99.0" # mcollective was removed in puppet 6 (5.99 indicates a pre-release version)
it { is_expected.to contain_service('mcollective') }
end
else
it { is_expected.to_not contain_service('puppet') }
it { is_expected.to_not contain_service('mcollective') }
Expand Down
7 changes: 4 additions & 3 deletions templates/install_puppet.bat.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ REM sets its startup type, which prevents installs from proceeding.
REM This may fail on agents without pxp-agent, but since this is not
REM run interactively and the next command sets ERRORLEVEL, it's OK.
net stop pxp-agent
REM Same for the Marionette Collective Service and Puppet Agent service
net stop mcollective
net stop puppet
REM Same for the <% @service_names.join(', ') %> services
<% @service_names.each do |service_name| %>
net stop <%= service_name %>
<% end %>

REM Log the current user token privileges for debugging
whoami /all
Expand Down
6 changes: 4 additions & 2 deletions templates/solaris_install.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ pkgadd -a <%= @adminfile %> -d <%= @sourcefile %> -G <%= @install_options.join('
# Ensure services are running. We do this on Solaris 10 b/c the installer cannot restart
# services on its own since that only happens when the service manifests change, which is
# highly unlikely in most agent upgrade scenarios.
start_service puppet
start_service mcollective

<% @service_names.each do |service_name| %>
start_service <%= service_name %>
<% end %>

0 comments on commit eff9218

Please sign in to comment.