Merge "Conform cgroups to systemd based services"

This commit is contained in:
Jenkins 2017-03-27 10:59:51 +00:00 committed by Gerrit Code Review
commit 7dc2405d31
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(
$cgroups_set = {},
$packages = $cgroups::params::packages,
)
inherits cgroups::params
{
) inherits cgroups::params {
validate_hash($cgroups_set)
ensure_packages($packages, { tag => 'cgroups' })
File {
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
notify => Service['cgconfig'],
}
file { '/etc/cgconfig.conf':
content => template('cgroups/cgconfig.conf.erb'),
notify => Service['cgconfigparser'],
tag => 'cgroups',
}
file { '/etc/cgrules.conf':
content => template('cgroups/cgrules.conf.erb'),
notify => Service['cgrulesengd'],
tag => 'cgroups',
}
file { '/etc/init.d/cgconfig':
mode => '0755',
source => "puppet:///modules/${module_name}/cgconfig.init",
tag => 'cgroups',
}
class { '::cgroups::service':
cgroups_settings => $cgroups_set,
}
Package <| tag == 'cgroups' |> ~>
Service['cgrulesengd']
Package <| tag == 'cgroups' |> -> File <| tag == 'cgroups' |>
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 {
'Debian': {
$packages = ['cgroup-bin', 'libcgroup1', 'cgroup-upstart']
$packages = ['cgroup-bin', 'libcgroup1']
}
default: {
fail("Unsupported platform")
}
}
}

View File

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

View File

@ -15,6 +15,7 @@ describe 'cgroups', :type => :class do
:owner => 'root',
:group => 'root',
:mode => '0644',
:notify => 'Service[cgconfig]',
:tag => 'cgroups',
}
end
@ -27,7 +28,7 @@ describe 'cgroups', :type => :class do
: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) }
end
@ -36,7 +37,6 @@ describe 'cgroups', :type => :class do
it { p catalogue.resource 'file', cg_file }
end
it { is_expected.to contain_file('/etc/cgrules.conf').that_notifies('Service[cgrulesengd]') }
it { is_expected.to contain_file('/etc/cgconfig.conf').that_notifies('Service[cgconfigparser]') }
it { is_expected.to contain_file('/etc/init.d/cgconfig').with(file_defaults.merge({:mode => '0755'})) }
end
end

View File

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