Merge "Rewrite service override to use policy-rc.d"

This commit is contained in:
Jenkins 2016-01-21 12:52:46 +00:00 committed by Gerrit Code Review
commit 9e8adc606b
6 changed files with 59 additions and 42 deletions

View File

@ -135,14 +135,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':
@ -322,14 +314,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']
}

View File

@ -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
}

View File

@ -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

View File

@ -1,3 +1,5 @@
fixtures:
forge_modules:
stdlib: "puppetlabs/stdlib"
symlinks:
'tweaks': "#{source_dir}"
tweaks: "#{source_dir}"

View File

@ -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 |>
}
}
}

View File

@ -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