diff --git a/manifests/init.pp b/manifests/init.pp index a22dac9..9ae8e8f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -10,6 +10,9 @@ $user_path_fix = undef, $mounts = {}, $groups = {}, + $cpu_limit = undef, + $memory_limit = undef, + $ubuntu_group_path = '/etc/cgconfig.conf', ) { # variables preparation @@ -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.') } @@ -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) @@ -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, + }), + } + } } diff --git a/metadata.json b/metadata.json index 78f8b26..3e5a5e2 100644 --- a/metadata.json +++ b/metadata.json @@ -27,6 +27,13 @@ "operatingsystemrelease": [ "11 SP2" ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "14.04", + "16.04" + ] } ], "requirements": [ diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 290e1f2..cecdc3b 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -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 @@ -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 diff --git a/spec/defines/group_spec.rb b/spec/defines/group_spec.rb index 18e8084..3fcdf18 100644 --- a/spec/defines/group_spec.rb +++ b/spec/defines/group_spec.rb @@ -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 diff --git a/templates/Ubuntu/cgconfig.conf.epp b/templates/Ubuntu/cgconfig.conf.epp new file mode 100644 index 0000000..98d2ba3 --- /dev/null +++ b/templates/Ubuntu/cgconfig.conf.epp @@ -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 %>"; + } +}