Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Optimized the limits files * Added a custom data type for service limits * Created a class for restarting the daemon so that other modules can use it cleanly * Updated tests Closes #17
- Loading branch information
1 parent
a032136
commit 0b13016
Showing
20 changed files
with
374 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
--- | ||
fixtures: | ||
repositories: | ||
stdlib: https://github.com/puppetlabs/puppetlabs-stdlib | ||
symlinks: | ||
systemd: "#{source_dir}" | ||
systemd: "#{source_dir}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--format documentation | ||
--color | ||
--fail-fast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
# -- Class systemd | ||
# This module allows triggering systemd commands once for all modules | ||
# This module allows triggering systemd commands once for all modules | ||
# | ||
# @api public | ||
# | ||
# @param service_limits | ||
# May be passed a resource hash suitable for passing directly into the | ||
# ``create_resources()`` function as called on ``systemd::service_limits`` | ||
# | ||
class systemd ( | ||
$service_limits = {} | ||
Optional[Hash] $service_limits = undef | ||
){ | ||
|
||
Exec { | ||
refreshonly => true, | ||
path => $::path, | ||
} | ||
|
||
exec { | ||
'systemctl-daemon-reload': | ||
command => 'systemctl daemon-reload', | ||
} | ||
include '::systemd::systemctl::daemon_reload' | ||
include '::systemd::tmpfiles' | ||
|
||
exec { | ||
'systemd-tmpfiles-create': | ||
command => 'systemd-tmpfiles --create', | ||
if $service_limits { | ||
create_resources('systemd::service_limits', $service_limits) | ||
} | ||
|
||
create_resources('systemd::service_limits', $service_limits, {}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,86 @@ | ||
# -- Define: systemd::service_limits | ||
# Creates a custom config file and reloads systemd | ||
# Adds a set of custom limits to the service | ||
# | ||
# @api public | ||
# | ||
# @see systemd.exec(5) | ||
# | ||
# @attr name [Pattern['^.+\.(service|socket|mount|swap)$']] | ||
# The name of the service that you will be modifying | ||
# | ||
# @param $ensure | ||
# Whether to drop a file or remove it | ||
# | ||
# @param path | ||
# The path to the main systemd settings directory | ||
# | ||
# @param limits | ||
# A Hash of service limits matching the settings in ``systemd.exec(5)`` | ||
# | ||
# * Mutually exclusive with ``$source`` | ||
# | ||
# @param source | ||
# A ``File`` resource compatible ``source`` | ||
# | ||
# * Mutually exclusive with ``$limits`` | ||
# | ||
# @param restart_service | ||
# Restart the managed service after setting the limits | ||
# | ||
define systemd::service_limits( | ||
$ensure = file, | ||
$path = '/etc/systemd/system', | ||
$limits = undef, | ||
$source = undef, | ||
$restart_service = true | ||
Enum['file','absent'] $ensure = 'file', | ||
Stdlib::Absolutepath $path = '/etc/systemd/system', | ||
Optional[Systemd::ServiceLimits] $limits = undef, | ||
Optional[String] $source = undef, | ||
Boolean $restart_service = true | ||
) { | ||
include ::systemd | ||
|
||
if $limits { | ||
validate_hash($limits) | ||
$content = template('systemd/limits.erb') | ||
if $title !~ Pattern['^.+\.(service|socket|mount|swap)$'] { | ||
fail('$name must match Pattern["^.+\.(service|socket|mount|swap)$"]') | ||
} | ||
|
||
if $limits and !empty($limits) { | ||
$_content = template("${module_name}/limits.erb") | ||
} | ||
else { | ||
$content = undef | ||
$_content = undef | ||
} | ||
|
||
if $limits and $source { | ||
if ($limits and !empty($limits)) and $source { | ||
fail('You may not supply both limits and source parameters to systemd::service_limits') | ||
} elsif $limits == undef and $source == undef { | ||
} | ||
elsif ($limits == undef or empty($limits)) and ($source == undef) { | ||
fail('You must supply either the limits or source parameter to systemd::service_limits') | ||
} | ||
|
||
file { "${path}/${title}.d/": | ||
ensure => 'directory', | ||
owner => 'root', | ||
group => 'root', | ||
} | ||
-> | ||
file { "${path}/${title}.d/limits.conf": | ||
ensure_resource('file', "${path}/${title}.d/", | ||
{ | ||
ensure => 'directory', | ||
owner => 'root', | ||
group => 'root', | ||
mode => '0644', | ||
} | ||
) | ||
|
||
file { "${path}/${title}.d/90-limits.conf": | ||
ensure => $ensure, | ||
content => $content, | ||
content => $_content, | ||
source => $source, | ||
owner => 'root', | ||
group => 'root', | ||
mode => '0444', | ||
notify => Exec['systemctl-daemon-reload'], | ||
mode => '0644', | ||
} | ||
|
||
File["${path}/${title}.d/90-limits.conf"] ~> Class['systemd::systemctl::daemon_reload'] | ||
|
||
if $restart_service { | ||
exec { "systemctl restart ${title}": | ||
exec { "restart ${title} because limits": | ||
command => "systemctl restart ${title}", | ||
path => $::path, | ||
refreshonly => true, | ||
subscribe => File["${path}/${title}.d/limits.conf"], | ||
require => Exec['systemctl-daemon-reload'], | ||
} | ||
|
||
File["${path}/${title}.d/90-limits.conf"] ~> Exec["restart ${title} because limits"] | ||
Class['systemd::systemctl::daemon_reload'] -> Exec["restart ${title} because limits"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Reload the systemctl daemon | ||
# | ||
# @api public | ||
class systemd::systemctl::daemon_reload { | ||
exec { 'systemctl-daemon-reload': | ||
command => 'systemctl daemon-reload', | ||
refreshonly => true, | ||
path => $::path, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
# -- Define: systemd::tmpfile | ||
# Creates a tmpfile and reloads systemd | ||
# Creates a systemd tmpfile | ||
# | ||
# @api public | ||
# | ||
# @see systemd-tmpfiles(8) | ||
# | ||
# @attr name [String] | ||
# The name of the tmpfile to create | ||
# | ||
# * May not contain ``/`` | ||
# | ||
# @param $ensure | ||
# Whether to drop a file or remove it | ||
# | ||
# @param path | ||
# The path to the main systemd tmpfiles directory | ||
# | ||
# @param content | ||
# The literal content to write to the file | ||
# | ||
# * Mutually exclusive with ``$source`` | ||
# | ||
# @param source | ||
# A ``File`` resource compatible ``source`` | ||
# | ||
# * Mutually exclusive with ``$limits`` | ||
# | ||
define systemd::tmpfile( | ||
$ensure = file, | ||
$path = '/etc/tmpfiles.d', | ||
$content = undef, | ||
$source = undef, | ||
Enum['file','absent'] $ensure = 'file', | ||
Stdlib::Absolutepath $path = '/etc/tmpfiles.d', | ||
Optional[String] $content = undef, | ||
Optional[String] $source = undef, | ||
) { | ||
include ::systemd | ||
|
||
if name =~ Pattern['/'] { | ||
fail('$name may not contain a forward slash "(/)"') | ||
} | ||
|
||
file { "${path}/${title}": | ||
ensure => $ensure, | ||
content => $content, | ||
source => $source, | ||
owner => 'root', | ||
group => 'root', | ||
mode => '0444', | ||
notify => Exec['systemd-tmpfiles-create'], | ||
mode => '0644', | ||
notify => Class['systemd::tmpfiles'], | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Update the systemd temp files | ||
# | ||
# @api public | ||
# | ||
# @see systemd-tmpfiles(8) | ||
# | ||
# @param operations | ||
# The operations to perform on the systemd tempfiles | ||
# | ||
# * All operations may be combined but you'll probably only ever want to | ||
# use ``create`` | ||
# | ||
class systemd::tmpfiles ( | ||
Array[Enum['create','clean','remove']] $operations = ['create'] | ||
) { | ||
|
||
$_ops = join($operations.map |$op| { "--${op}" }, ' ') | ||
|
||
exec { 'systemd-tmpfiles': | ||
command => "systemd-tmpfiles ${_ops}", | ||
refreshonly => true, | ||
path => $::path, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,60 @@ | ||
# -- Define: systemd::unit_file | ||
# Creates a unit file and reloads systemd | ||
# Creates a systemd unit file | ||
# | ||
# @api public | ||
# | ||
# @see systemd.unit(5) | ||
# | ||
# @attr name [Pattern['^.+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$']] | ||
# The target unit file to create | ||
# | ||
# * Must not contain ``/`` | ||
# | ||
# @attr path | ||
# The main systemd configuration path | ||
# | ||
# @attr content | ||
# The full content of the unit file | ||
# | ||
# * Mutually exclusive with ``$source`` | ||
# | ||
# @attr source | ||
# The ``File`` resource compatible ``source`` | ||
# | ||
# * Mutually exclusive with ``$content`` | ||
# | ||
# @attr target | ||
# If set, will force the file to be a symlink to the given target | ||
# | ||
# * Mutually exclusive with both ``$source`` and ``$content`` | ||
# | ||
define systemd::unit_file( | ||
$ensure = file, | ||
$path = '/etc/systemd/system', | ||
$content = undef, | ||
$source = undef, | ||
$target = undef, | ||
Enum['file', 'absent'] $ensure = 'file', | ||
Stdlib::Absolutepath $path = '/etc/systemd/system', | ||
Optional[String] $content = undef, | ||
Optional[String] $source = undef, | ||
Optional[Stdlib::Absolutepath] $target = undef, | ||
) { | ||
include ::systemd | ||
|
||
if $title !~ Pattern['^.+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$'] { | ||
fail('$name must match Pattern["^.+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$"]') | ||
} | ||
|
||
if $target { | ||
$_ensure = 'link' | ||
} | ||
else { | ||
$_ensure = $ensure | ||
} | ||
|
||
file { "${path}/${title}": | ||
ensure => $ensure, | ||
ensure => $_ensure, | ||
content => $content, | ||
source => $source, | ||
target => $target, | ||
owner => 'root', | ||
group => 'root', | ||
mode => '0444', | ||
notify => Exec['systemctl-daemon-reload'], | ||
mode => '0644', | ||
notify => Class['systemd::systemctl::daemon_reload'], | ||
} | ||
} |
Oops, something went wrong.