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/<servicename>.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
This commit is contained in:
parent
8e24554e6d
commit
143d574edf
@ -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': }
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1,3 +1,5 @@
|
||||
fixtures:
|
||||
forge_modules:
|
||||
stdlib: "puppetlabs/stdlib"
|
||||
symlinks:
|
||||
'tweaks': "#{source_dir}"
|
||||
tweaks: "#{source_dir}"
|
||||
|
@ -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 |>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user