Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
$user_path_fix = undef,
$mounts = {},
$groups = {},
$cpu_limit = undef,
$memory_limit = undef,
$ubuntu_group_path = '/etc/cgconfig.conf',
) {

# variables preparation
Expand All @@ -34,6 +37,20 @@
}
}
}
'Debian': {
case $::operatingsystemmajrelease {
'14.04','16.04': {
$package_name_default = [
'libcgroup1',
'cgroup-bin',
'cgroup-lite',
]
}
default: {
fail('cgroups is only supported on Ubuntu 14.04 and 16.04.')
}
}
}
default: {
fail('cgroups is not supported on this platform.')
}
Expand Down Expand Up @@ -71,17 +88,21 @@
ensure => present,
}

file { $config_file_path:
ensure => file,
notify => Service[$service_name],
content => template('cgroups/cgroup.conf.erb'),
require => Package[$package_name_real],
if ($::osfamily != 'Debian') {
file { $config_file_path:
ensure => file,
notify => Service[$service_name],
content => template('cgroups/cgroup.conf.erb'),
require => Package[$package_name_real],
}
}

service { $service_name:
ensure => running,
enable => true,
require => Package[$package_name_real],
if ($::osfamily != 'Debian') {
service { $service_name:
ensure => running,
enable => true,
require => Package[$package_name_real],
}
}

create_resources('cgroups::group', $groups)
Expand All @@ -94,4 +115,14 @@
require => Service[$service_name],
}
}

if ($::osfamily == 'Debian') {
file { $ubuntu_group_path:
ensure => file,
content => epp('cgroups/Ubuntu/cgconfig.conf.epp', {
cpu_limit => $cpu_limit,
memory_limit => $memory_limit,
}),
}
}
}
7 changes: 7 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
"operatingsystemrelease": [
"11 SP2"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"14.04",
"16.04"
]
}
],
"requirements": [
Expand Down
15 changes: 12 additions & 3 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
require 'spec_helper'
describe 'cgroups' do
['Debian', 'RedHat'].each do |osfamily|
['7.1', '14.04', '16.04'].each do |operatingsystemrelease|
['7', '14.04', '16.04'].each do |operatingsystemmajrelease|
let(:facts) do
{
:operatingsystemmajrelease => '7',
:operatingsystemrelease => '7.2',
:osfamily => 'RedHat',
:operatingsystemmajrelease => operatingsystemmajrelease,
:operatingsystemrelease => operatingsystemrelease,
:osfamily => osfamily,
}
end

Expand All @@ -21,6 +24,12 @@
:osfamily => 'Suse',
:package_name => 'libcgroup1',
},
'Ubuntu' => {
:operatingsystemmajrelease => '14.04'
:operatingsystemrelease => '14.04',
:osfamily => 'Debian',
:package_name => 'libcgroup1',
},
}

describe 'with defaults for all parameters' do
Expand Down
9 changes: 6 additions & 3 deletions spec/defines/group_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
require 'spec_helper'
describe 'cgroups::group' do
let(:title) { 'rspec/test' }
['Debian', 'RedHat'].each do |osfamily|
['7.1', '14.04', '16.04'].each do |operatingsystemrelease|
['7', '14.04', '16.04'].each do |operatingsystemmajrelease|
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '7.1',
:operatingsystemmajrelease => '7',
:osfamily => osfamily,
:operatingsystemrelease => operatingsystemrelease,
:operatingsystemmajrelease => operatingsystemmajrelease,
}
end
context 'with defaults for all parameters' do
Expand Down
21 changes: 21 additions & 0 deletions templates/Ubuntu/cgconfig.conf.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is being maintained by Puppet.
# DO NOT EDIT

group limitgroup {
perm {
admin {
uid = root;
gid = root;
}
task {
uid = 500;
gid = 500;
}
}
cpu {
cpu.shares = "<%= $cpu_limit %>";
}
memory {
memory.limit_in_bytes = "<%= $memory_limit %>";
}
}