Conform cgroups to systemd based services

Update cgroups configuration to be running on ubuntu 16.04.
Remove "cgroup-lite" package/service since systemd
mounts cgroups sanely itself.

Change-Id: I250f1ba92fbe1ceac415a73b640fd00d6e2898e4
Closes-Bug: #1669747
This commit is contained in:
Michael Polenchuk 2017-03-09 14:06:18 +04:00
parent 77320dedde
commit 4f33d4aabb
6 changed files with 89 additions and 45 deletions

View File

@ -0,0 +1,66 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: cgconfig
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Configures CGroups
### END INIT INFO
start_service() {
if is_running; then
echo "cgrulesengd is running already!"
return 1
else
echo "Processing /etc/cgconfig.conf ..."
cgconfigparser -l /etc/cgconfig.conf
echo "Processing /etc/cgrules.conf ..."
cgrulesengd -vvv --logfile=/var/log/cgrulesengd.log
return 0
fi
}
stop_service() {
if is_running; then
echo "Stopping cgrulesengd ..."
pkill cgrulesengd
else
echo "cgrulesengd is not running!"
return 1
fi
}
status() {
if pgrep cgrulesengd > /dev/null; then
echo "cgrulesengd is running"
return 0
else
echo "cgrulesengd is not running!"
return 3
fi
}
is_running() {
status >/dev/null 2>&1
}
case "${1:-}" in
start)
start_service
;;
stop)
stop_service
;;
status)
status
;;
*)
echo "Usage: /etc/init.d/cgconfig {start|stop|restart|status}"
exit 2
;;
esac
exit $?

View File

@ -13,51 +13,40 @@
class cgroups( class cgroups(
$cgroups_set = {}, $cgroups_set = {},
$packages = $cgroups::params::packages, $packages = $cgroups::params::packages,
) ) inherits cgroups::params {
inherits cgroups::params
{
validate_hash($cgroups_set) validate_hash($cgroups_set)
ensure_packages($packages, { tag => 'cgroups' }) ensure_packages($packages, { tag => 'cgroups' })
File { File {
ensure => file, ensure => file,
owner => 'root', owner => 'root',
group => 'root', group => 'root',
mode => '0644', mode => '0644',
notify => Service['cgconfig'],
} }
file { '/etc/cgconfig.conf': file { '/etc/cgconfig.conf':
content => template('cgroups/cgconfig.conf.erb'), content => template('cgroups/cgconfig.conf.erb'),
notify => Service['cgconfigparser'],
tag => 'cgroups', tag => 'cgroups',
} }
file { '/etc/cgrules.conf': file { '/etc/cgrules.conf':
content => template('cgroups/cgrules.conf.erb'), content => template('cgroups/cgrules.conf.erb'),
notify => Service['cgrulesengd'],
tag => 'cgroups', tag => 'cgroups',
} }
file { '/etc/init.d/cgconfig':
mode => '0755',
source => "puppet:///modules/${module_name}/cgconfig.init",
tag => 'cgroups',
}
class { '::cgroups::service': class { '::cgroups::service':
cgroups_settings => $cgroups_set, cgroups_settings => $cgroups_set,
} }
Package <| tag == 'cgroups' |> ~> Package <| tag == 'cgroups' |> -> File <| tag == 'cgroups' |>
Service['cgrulesengd'] Service['cgconfig'] -> Cgclassify <||>
Package <| tag == 'cgroups' |> ->
File <| tag == 'cgroups' |>
File <| tag == 'cgroups' |> ->
Service['cgroup-lite']
Service['cgroup-lite'] ->
Service['cgconfigparser']
Service['cgconfigparser'] ->
Cgclassify <||>
Cgclassify <||> ->
Service['cgrulesengd']
} }

View File

@ -2,10 +2,11 @@ class cgroups::params {
case $::osfamily { case $::osfamily {
'Debian': { 'Debian': {
$packages = ['cgroup-bin', 'libcgroup1', 'cgroup-upstart'] $packages = ['cgroup-bin', 'libcgroup1']
} }
default: { default: {
fail("Unsupported platform") fail("Unsupported platform")
} }
} }
} }

View File

@ -1,26 +1,16 @@
class cgroups::service ( class cgroups::service (
$cgroups_settings = {}, $cgroups_settings = {},
) ) {
{
service { 'cgroup-lite':
ensure => running,
enable => true,
}
service { 'cgconfigparser': service { 'cgconfig':
ensure => running, ensure => running,
hasstatus => false, enable => true,
status => '/bin/true', provider => 'init',
restart => 'service cgconfigparser restart',
require => Service['cgroup-lite'],
}
service { 'cgrulesengd':
ensure => running,
} }
$cgclass_res = map_cgclassify_opts($cgroups_settings) $cgclass_res = map_cgclassify_opts($cgroups_settings)
unless empty($cgclass_res) { unless empty($cgclass_res) {
create_resources('cgclassify', $cgclass_res, { 'ensure' => present }) create_resources('cgclassify', $cgclass_res, { 'ensure' => present })
} }
} }

View File

@ -15,6 +15,7 @@ describe 'cgroups', :type => :class do
:owner => 'root', :owner => 'root',
:group => 'root', :group => 'root',
:mode => '0644', :mode => '0644',
:notify => 'Service[cgconfig]',
:tag => 'cgroups', :tag => 'cgroups',
} }
end end
@ -27,7 +28,7 @@ describe 'cgroups', :type => :class do
:cgroups_settings => params[:cgroups_set]) :cgroups_settings => params[:cgroups_set])
} }
%w(libcgroup1 cgroup-bin cgroup-upstart).each do |cg_pkg| %w(libcgroup1 cgroup-bin).each do |cg_pkg|
it { is_expected.to contain_package(cg_pkg) } it { is_expected.to contain_package(cg_pkg) }
end end
@ -36,7 +37,6 @@ describe 'cgroups', :type => :class do
it { p catalogue.resource 'file', cg_file } it { p catalogue.resource 'file', cg_file }
end end
it { is_expected.to contain_file('/etc/cgrules.conf').that_notifies('Service[cgrulesengd]') } it { is_expected.to contain_file('/etc/init.d/cgconfig').with(file_defaults.merge({:mode => '0755'})) }
it { is_expected.to contain_file('/etc/cgconfig.conf').that_notifies('Service[cgconfigparser]') }
end end
end end

View File

@ -9,8 +9,6 @@ describe 'cgroups::service', :type => :class do
} }
end end
%w(cgroup-lite cgconfigparser cgrulesengd).each do |cg_service| it { is_expected.to contain_service('cgconfig') }
it { is_expected.to contain_service(cg_service) }
end
end end
end end