-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for drop-in files The drop-in directory must not created more then once, even if multiple drop-in files per unit are created. Also drop-in files for units, which are not deployed via puppet, should be supported. The only solution is to use ensure_resource from puppetlabs/stdlib. Everything else is the same as for a unit_file, except the name of the drop-in file, which has to end with '.conf'. * Add spec tests for dropin_file * Update README with the drop-in file feature * Typo Fixes * Fix broken spec test
- Loading branch information
1 parent
047b31d
commit 0e4281a
Showing
4 changed files
with
145 additions
and
0 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
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,69 @@ | ||
# Creates a drop-in file for a systemd unit | ||
# | ||
# @api public | ||
# | ||
# @see systemd.unit(5) | ||
# | ||
# @attr name [Pattern['^.+\.conf$']] | ||
# 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::dropin_file( | ||
Systemd::Unit $unit, | ||
Enum['present', 'absent', 'file'] $ensure = 'present', | ||
Stdlib::Absolutepath $path = '/etc/systemd/system', | ||
Optional[String] $content = undef, | ||
Optional[String] $source = undef, | ||
Optional[Stdlib::Absolutepath] $target = undef, | ||
) { | ||
include ::systemd | ||
|
||
assert_type(Systemd::Dropin, $name) | ||
|
||
if $target { | ||
$_ensure = 'link' | ||
} else { | ||
$_ensure = $ensure ? { | ||
'present' => 'file', | ||
default => $ensure, | ||
} | ||
} | ||
|
||
if $ensure != 'absent' { | ||
ensure_resource('file', "${path}/${unit}.d", { | ||
ensure => directory, | ||
owner => 'root', | ||
group => 'root', | ||
}) | ||
} | ||
|
||
file { "${path}/${unit}.d/${name}": | ||
ensure => $_ensure, | ||
content => $content, | ||
source => $source, | ||
target => $target, | ||
owner => 'root', | ||
group => 'root', | ||
mode => '0444', | ||
notify => Class['systemd::systemctl::daemon_reload'], | ||
} | ||
} |
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,42 @@ | ||
require 'spec_helper' | ||
|
||
describe 'systemd::dropin_file' do | ||
context 'supported operating systems' do | ||
on_supported_os.each do |os, facts| | ||
context "on #{os}" do | ||
let(:facts) { facts } | ||
|
||
let(:title) { 'test.conf' } | ||
|
||
let(:params) {{ | ||
:unit => 'test.service', | ||
:content => 'random stuff' | ||
}} | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
|
||
it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d").with( | ||
:ensure => 'directory', | ||
) } | ||
|
||
it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").with( | ||
:ensure => 'file', | ||
:content => /#{params[:content]}/, | ||
:mode => '0444' | ||
) } | ||
|
||
it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").that_notifies('Class[systemd::systemctl::daemon_reload]') } | ||
|
||
context 'with a bad unit type' do | ||
let(:title) { 'test.badtype' } | ||
|
||
it { | ||
expect{ | ||
is_expected.to compile.with_all_deps | ||
}.to raise_error(/expects a match for Systemd::Dropin/) | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
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 @@ | ||
type Systemd::Dropin = Pattern['^.+\.conf$'] |