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
127 changes: 112 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ Manage cgroups configuration service and files.
- /etc/cgconfig.conf
- /etc/cgconfig.d/*.conf

# Compatibility
## Compatibility

This module has been tested to work on the following systems with Puppet v3
(with and without the future parser) and Puppet v4 (with strict variables)
using Ruby versions 1.8.7 (Puppet v3 only), 1.9.3, 2.0.0, 2.1.0 and 2.3.1.

* EL 6
* EL 7
* SLED 11 SP2
* SLES 11 SP2
- EL 6
- EL 7
- SLED 11 SP2
- SLES 11 SP2

[![Build Status](https://travis-ci.org/Ericsson/puppet-module-cgroups.png?branch=master)](https://travis-ci.org/Ericsson/puppet-module-cgroups)

Expand All @@ -27,24 +27,31 @@ The `cgroups` class is used to configure the cgroup service and its main configu
### Parameters

---

#### cgconfig_content (string)

Optional, specify arbitary content for the cgconfig.conf file that will be included at the bottom.

- *Default*: undef

---

#### config_file_path (string)

Absolute path to cgroups config file.

- *Default*: '/etc/cgconfig.conf'

---

#### groups (hash)

A hash containing group resources to be configured (see below for cgroups::group resources)

- *Default*: undef

##### Example:
##### Example

```yaml
cgroups::groups:
"user/mgw-all":
Expand All @@ -61,7 +68,8 @@ cgroups::groups:
"cpuset.cpus": "0,1"
```

##### Hiera example with Suse 11.2 bugfix:
##### Hiera example with Suse 11.2 bugfix

```yaml
cgroups::user_path_fix: '/sys/fs/cgroup/user/mgw-all'
cgroups::groups:
Expand All @@ -78,38 +86,116 @@ cgroups::groups:
"cpuset.mems": "0"
"cpuset.cpus": "0,1"
```

---

#### mounts (hash)

A hash containing mounts to be configured in /etc/cgconfig.conf.
NOTE: On systemd managed systems, the default resource controllers are the domain of systemd, therefore this setting should probably not be used unless you are managing a controller not yet supported by systemd such as net_prio.

- *Default*: undef

##### Example:
##### Example

```yaml
cgroups::mounts:
cpu: '/cgroup'
```

---

#### package_name (string or array)

Name of package(s) that enables cgroups. Only set it to overwrite the modules defaults: RedHat 'libcgroup', Suse 'libcgroup1'.

- *Default*: undef

---

#### service_name (string)

Name of service to manage.

- *Default*: 'cgconfig'

---

#### user_path_fix (string)

Absolute path to set 0775 permissions on when defined. This is a fix for Suse that have a bug in setting this though the config file. Only available on Suse.

- *Default*: undef

---

#### rules_file_path (string)

Absolute path to cgroups rules config file.

- *Default*: '/etc/cgrules.conf'

---

#### rules_service_name (string)

Name of the rules service to manage.

- *Default*: 'cgred'

---

#### rules_service_enable (boolean)

A boolean to decide whether the rules service should be enabled or not.

- *Default*: false

---

#### rules_service_ensure (string)

The state that shoudl be enforced for the rules service.

- *Default*: 'stopped'

---

#### rules (hash)

An optional hash containing rules for the `cgrules.conf` file. Note that the keys of the hash are the `user` values (one per line in the configuration file), and the `controllers` and `destination` elements of the next level of each hash are required.

- *Default*: undef

##### rules Example

```puppet
rules => {
'@template1' => {
controllers => 'cpu,cpuacct,memory',
destination => 'template1/%u',
},
'@template2' => {
controllers => 'cpu,cpuacct,memory',
destination => 'template2/%u',
},
},
```

##### Hiera rules example

```yaml
cgroups::rules:
'@template1':
controllers: 'cpu,cpuacct,memory'
destination: 'template1/%u'
'@template2':
controllers: 'cpu,cpuacct,memory'
destination: 'template2/%u'
```

---

## Defined type `cgroups::group`

### Description
Expand All @@ -121,29 +207,35 @@ You can also specify `cgroups::groups` from hiera as a hash of group resources a
### Parameters

---

#### controllers (hash)

An optional hash containing the controllers for the group.

- *Default*: undef

##### Example:
```yaml
##### Example

```puppet
controllers => {
'cpuset' => {
'cpuset' => {
'cpuset.mems' => '0',
'cpuset.cpus' => '0,1'
}
}
```

---

#### permissions (hash)

An optional hash containing permissions for the group.

- *Default*: undef

##### Example:
```yaml
##### Example

```puppet
permissions => {
'task' => {
'uid' => 'root',
Expand All @@ -155,16 +247,20 @@ An optional hash containing permissions for the group.
},
}
```

---

#### target_path (string)

Optional parameter to define in which path the configuration file should be put. By default the module will use the /etc/cgconfig.d directory.

- *Default*: '/etc/cgconfig.d'

---

### Full example
```yaml

```puppet
cggroups::group { 'mgw/user':
permissions => {
'task' => {
Expand All @@ -177,11 +273,12 @@ cggroups::group { 'mgw/user':
},
},
controllers => {
'cpuset' => {
'cpuset' => {
'cpuset.mems' => '0',
'cpuset.cpus' => '0,1'
}
}
}
```

---
5 changes: 4 additions & 1 deletion manifests/group.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
file { $target:
ensure => file,
content => template('cgroups/group.conf.erb'),
notify => Service[$cgroups::service_name],
notify => [
Service[$cgroups::service_name],
Service[$cgroups::rules_service_name],
],
}
}
50 changes: 41 additions & 9 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
# Manage cgroups configuration service and files.
#
class cgroups (
$config_file_path = '/etc/cgconfig.conf',
$service_name = 'cgconfig',
$package_name = undef,
$cgconfig_content = undef,
$user_path_fix = undef,
$mounts = {},
$groups = {},
$config_file_path = '/etc/cgconfig.conf',
$rules_file_path = '/etc/cgrules.conf',
$service_name = 'cgconfig',
$rules_service_name = 'cgred',
$rules_service_enable = false,
$rules_service_ensure = 'stopped',
$package_name = undef,
$cgconfig_content = undef,
$user_path_fix = undef,
$mounts = {},
$groups = {},
$rules = {},
) {

# variables preparation
Expand Down Expand Up @@ -51,6 +56,10 @@
fail('cgroups::service_name is not a string.')
}

if is_string($rules_service_name) == false {
fail('cgroups::rules_service_name is not a string.')
}

if is_string($package_name_real) == false and is_array($package_name_real) == false {
fail('cgroups::package_name is not a string or an array.')
}
Expand All @@ -65,6 +74,7 @@

validate_hash($mounts)
validate_hash($groups)
validate_hash($rules)

# functionality
package { $package_name_real:
Expand All @@ -73,25 +83,47 @@

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

file { $rules_file_path:
ensure => file,
notify => [
Service[$service_name],
Service[$rules_service_name],
],
content => template('cgroups/cgrules.conf.erb'),
require => Package[$package_name_real],
}

service { $service_name:
ensure => running,
enable => true,
require => Package[$package_name_real],
}

service { $rules_service_name:
ensure => $rules_service_ensure,
enable => $rules_service_enable,
require => Package[$package_name_real],
}

create_resources('cgroups::group', $groups)

if ($user_path_fix != undef) and ($::osfamily == 'Suse') {
file { 'cgroups_path_fix':
ensure => directory,
path => $user_path_fix,
mode => '0775',
require => Service[$service_name],
require => [
Service[$service_name],
Service[$rules_service_name],
],
}
}
}
Loading