From 143d574edf6fb52bdce7fec2823c9d4067c5fa9e Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Fri, 8 Jan 2016 14:28:56 -0700 Subject: [PATCH] Rewrite service override to use policy-rc.d The override file in Debian based systems will only prevent the service from being started if the service has a configuration file[0] in /etc/init. Since not all services may have a config file, the better way to prevent services from starting as part of the installation process is to use a policy-rc.d file[1]. This change replaces the use of /etc/init/.override with the creation of a /usr/sbin/policy-rc.d file durring the installation process. This change also includes an update to the galera module where we were previously utilizing the policy-rc.d method for mysql server. [0] http://manpages.ubuntu.com/manpages/trusty/man5/init.5.html [1] https://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt Change-Id: I8e09e1403c554b2b8fae6fe915590d7235ce9b99 Closes-Bug: #1532331 Related-Blueprint: deploy-with-uca-packages --- deployment/puppet/galera/manifests/init.pp | 15 +---- .../puppet/galera/spec/shared-examples.rb | 1 - .../galera/spec/unit/classes/init_spec.rb | 2 - deployment/puppet/tweaks/.fixtures.yml | 4 +- .../manifests/ubuntu_service_override.pp | 63 +++++++++++++------ .../tweaks_ubuntu_service_override_spec.rb | 18 ++++-- 6 files changed, 60 insertions(+), 43 deletions(-) diff --git a/deployment/puppet/galera/manifests/init.pp b/deployment/puppet/galera/manifests/init.pp index 736bed53c1..5da0a3a275 100644 --- a/deployment/puppet/galera/manifests/init.pp +++ b/deployment/puppet/galera/manifests/init.pp @@ -118,14 +118,6 @@ class galera ( } if ($use_percona and $::operatingsystem == 'Ubuntu') { - # Disable service autostart - file { '/usr/sbin/policy-rc.d': - ensure => present, - content => inline_template("#!/bin/sh\nexit 101\n"), - mode => '0755', - before => Package['MySQL-server'] - } - #FIXME: #Remove this after https://bugs.launchpad.net/bugs/1461304 will be fixed file {'/etc/apt/apt.conf.d/99tmp': @@ -305,14 +297,9 @@ class galera ( if ($use_percona and $::operatingsystem == 'Ubuntu') { #Clean tmp files: - exec { 'rm-policy-rc.d': - command => '/bin/rm /usr/sbin/policy-rc.d', - } exec {'rm-99tmp': command => '/bin/rm /etc/apt/apt.conf.d/99tmp', } - Exec['wait-for-synced-state'] -> - Exec['rm-policy-rc.d'] Exec['wait-for-synced-state'] -> Exec['rm-99tmp'] } @@ -321,7 +308,7 @@ class galera ( Service['mysql'] -> Exec['wait-initial-sync'] -> Exec['wait-for-synced-state'] -> - Exec ['rm-init-file'] + Exec['rm-init-file'] Package['MySQL-server'] ~> Exec['wait-initial-sync'] anchor {'database-cluster-done': } diff --git a/deployment/puppet/galera/spec/shared-examples.rb b/deployment/puppet/galera/spec/shared-examples.rb index c4cfc1f5a8..9af998e358 100644 --- a/deployment/puppet/galera/spec/shared-examples.rb +++ b/deployment/puppet/galera/spec/shared-examples.rb @@ -41,7 +41,6 @@ shared_examples 'test-files' do |params| should contain_file('/etc/mysql/conf.d/wsrep.cnf') should contain_file('/tmp/wsrep-init-file') if params[:use_percona_packages] and facts[:operatingsystem] == 'Ubuntu' - should contain_file('/usr/sbin/policy-rc.d') should contain_file('/etc/apt/apt.conf.d/99tmp') end } diff --git a/deployment/puppet/galera/spec/unit/classes/init_spec.rb b/deployment/puppet/galera/spec/unit/classes/init_spec.rb index 255df2d6f4..f7dc454bfb 100644 --- a/deployment/puppet/galera/spec/unit/classes/init_spec.rb +++ b/deployment/puppet/galera/spec/unit/classes/init_spec.rb @@ -34,7 +34,6 @@ describe 'galera', :type => :class do # the package installation on Ubuntu let(:params) { p } it { - should contain_exec('rm-policy-rc.d') should contain_exec('rm-99tmp') } end @@ -59,7 +58,6 @@ describe 'galera', :type => :class do # the package installation on Ubuntu let(:params) { p } it { - should contain_exec('rm-policy-rc.d') should contain_exec('rm-99tmp') } end diff --git a/deployment/puppet/tweaks/.fixtures.yml b/deployment/puppet/tweaks/.fixtures.yml index 0bca348d61..0119c57693 100644 --- a/deployment/puppet/tweaks/.fixtures.yml +++ b/deployment/puppet/tweaks/.fixtures.yml @@ -1,3 +1,5 @@ fixtures: + forge_modules: + stdlib: "puppetlabs/stdlib" symlinks: - 'tweaks': "#{source_dir}" + tweaks: "#{source_dir}" diff --git a/deployment/puppet/tweaks/manifests/ubuntu_service_override.pp b/deployment/puppet/tweaks/manifests/ubuntu_service_override.pp index f51c1e9391..4764bee359 100644 --- a/deployment/puppet/tweaks/manifests/ubuntu_service_override.pp +++ b/deployment/puppet/tweaks/manifests/ubuntu_service_override.pp @@ -1,32 +1,57 @@ +# == Type: tweaks::ubuntu_service_override +# +# Disable services from starting when the package is installed on Ubuntu OS +# +# == Parameters +# +# [*service_name*] +# The name of the service that is associated with the package being installed. +# Defaults to $name +# +# [*package_name*] +# The name of the package that is being installed that has a service to be +# prevented from being started as part of the installation process. +# Defaults to $name +# define tweaks::ubuntu_service_override ( $service_name = $name, $package_name = $name, ) { if $::operatingsystem == 'Ubuntu' { - $override_file = "/etc/init/${service_name}.override" - $file_name = "create_${service_name}_override" - $exec_name = "remove_${service_name}_override" - if ! is_pkg_installed($package_name) { - file { $file_name : + # https://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt + # use policy-rc.d to really ensure services don't get started on + # installation as service override files are only used if a job + # configuration file exists (see man 5 init) + $policyrc_file = '/usr/sbin/policy-rc.d' + + # use ensure resource as we only want a single instance of the + # policy-rc.d file in the catalog + ensure_resource('file', 'create-policy-rc.d', { ensure => present, - path => $override_file, - content => 'manual', - mode => '0644', + path => $policyrc_file, + content => "#!/bin/bash\nexit 101", + mode => '0755', owner => 'root', - group => 'root', - } - - exec { $exec_name : + group => 'root' + }) + # use ensure resource as we only want a single remove exec in the catalog + ensure_resource('exec', 'remove-policy-rc.d', { path => [ '/sbin', '/bin', '/usr/bin', '/usr/sbin' ], - command => "rm -f ${override_file}", - onlyif => "test -f ${override_file}", - } + command => "rm -f ${policyrc_file}", + onlyif => "test -f ${policyrc_file}", + }) - File[$file_name] -> Package <| name == $package_name |> -> Exec[$exec_name] - File[$file_name] -> Package <| title == $package_name |> -> Exec[$exec_name] - Exec[$exec_name] -> Service <| name == $service_name |> - Exec[$exec_name] -> Service <| title == $service_name |> + File['create-policy-rc.d'] -> + Package <| name == $package_name |> -> + Exec['remove-policy-rc.d'] + File['create-policy-rc.d'] -> + Package <| title == $package_name |> -> + Exec['remove-policy-rc.d'] + Exec['remove-policy-rc.d'] -> + Service <| name == $service_name |> + Exec['remove-policy-rc.d'] -> + Service <| title == $service_name |> } } } diff --git a/deployment/puppet/tweaks/spec/defines/tweaks_ubuntu_service_override_spec.rb b/deployment/puppet/tweaks/spec/defines/tweaks_ubuntu_service_override_spec.rb index f41995eff5..f58cf407c9 100644 --- a/deployment/puppet/tweaks/spec/defines/tweaks_ubuntu_service_override_spec.rb +++ b/deployment/puppet/tweaks/spec/defines/tweaks_ubuntu_service_override_spec.rb @@ -22,13 +22,19 @@ describe 'tweaks::ubuntu_service_override' do it 'configures with the default params' do should contain_tweaks__ubuntu_service_override(title) if facts[:operatingsystem] == 'Ubuntu' - should contain_file("create_#{params[:service_name]}_override").with( - :path => "/etc/init/#{title}.override") - should contain_exec("remove_#{params[:service_name]}_override") + should contain_file('create-policy-rc.d').with( + :ensure => 'present', + :path => '/usr/sbin/policy-rc.d', + :content => "#!/bin/bash\nexit 101", + :mode => '0755', + :owner => 'root', + :group => 'root') + should contain_exec('remove-policy-rc.d').with( + :command => 'rm -f /usr/sbin/policy-rc.d', + :onlyif => 'test -f /usr/sbin/policy-rc.d') else - should_not contain_file("create_#{params[:service_name]}_override").with( - :path => "/etc/init.d/#{title}.override") - should_not contain_exec("remove_#{params[:service_name]}_override") + should_not contain_file('create-policy-rc.d') + should_not contain_exec('remove-policy-rc.d') end end end