Showing with 269 additions and 64 deletions.
  1. +1 −0 .fixtures.yml
  2. +54 −18 CHANGELOG.md
  3. +34 −8 README.md
  4. +27 −4 lib/facter/systemd.rb
  5. +29 −7 manifests/init.pp
  6. +2 −2 manifests/networkd.pp
  7. +1 −1 manifests/resolved.pp
  8. +66 −0 manifests/timesyncd.pp
  9. +1 −1 metadata.json
  10. +24 −0 spec/classes/init_spec.rb
  11. +10 −0 spec/default_module_facts.yaml
  12. +2 −0 spec/spec_helper.rb
  13. +18 −23 spec/unit/facter/systemd_spec.rb
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
fixtures:
repositories:
stdlib: https://github.com/puppetlabs/puppetlabs-stdlib
inifile: https://github.com/puppetlabs/puppetlabs-inifile
symlinks:
systemd: "#{source_dir}"
72 changes: 54 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,63 @@
# Change Log
# Changelog



## [1.1.0](https://github.com/camptocamp/puppet-systemd/tree/1.1.0) (2017-10-17)

[Full Changelog](https://github.com/camptocamp/puppet-systemd/compare/1.0.0...1.1.0)

**Closed issues:**

- Add explicit ordering to README.md [\#24](https://github.com/camptocamp/puppet-systemd/issues/24)
- Manage drop-in files [\#15](https://github.com/camptocamp/puppet-systemd/issues/15)

**Merged pull requests:**

- Add systemd-timesyncd support [\#43](https://github.com/camptocamp/puppet-systemd/pull/43) ([bastelfreak](https://github.com/bastelfreak))
- Reuse the service\_provider fact from stdlib [\#42](https://github.com/camptocamp/puppet-systemd/pull/42) ([ekohl](https://github.com/ekohl))
- \(doc\) Adds examples of running the service created [\#29](https://github.com/camptocamp/puppet-systemd/pull/29) ([petems](https://github.com/petems))
- Quote hash keys in example of service limits [\#20](https://github.com/camptocamp/puppet-systemd/pull/20) ([stbenjam](https://github.com/stbenjam))

## [1.0.0](https://github.com/camptocamp/puppet-systemd/tree/1.0.0) (2017-09-04)

## [1.0.0](https://forge.puppetlabs.com/camptocamp/systemd/1.0.0) (2017-09-04)
[Full Changelog](https://github.com/camptocamp/puppet-systemd/compare/0.4.0...1.0.0)

- Refactor systemd facts [\#12](https://github.com/camptocamp/puppet-systemd/pull/12) ([petems](https://github.com/petems))
- Manage resource limits of services [\#13](https://github.com/camptocamp/puppet-systemd/pull/13) ([ruriky](https://github.com/ruriky))
- Remove Puppet 3 tests
- Add MemoryLimit to limits template [\#23](https://github.com/camptocamp/puppet-systemd/pull/23) ([pkilambi](https://github.com/pkilambi))
- Linting
- Add seltype to systemd directory [\#27](https://github.com/camptocamp/puppet-systemd/pull/27) ([petems](https://github.com/petems))
- Add management for systemd-resolved [\#31](https://github.com/camptocamp/puppet-systemd/pull/31) ([bastelfreak](https://github.com/bastelfreak))
- Add a network defined resource [\#30](https://github.com/camptocamp/puppet-systemd/pull/30) ([bastelfreak](https://github.com/bastelfreak))
- Support for Puppet 4 [\#18](https://github.com/camptocamp/puppet-systemd/pull/18) ([trevor-vaughan](https://github.com/trevor-vaughan))
- Add Puppet4 datatypes [\#32](https://github.com/camptocamp/puppet-systemd/pull/32) ([bastelfreak](https://github.com/bastelfreak))
- Add control group limits to ServiceLimits [\#36](https://github.com/camptocamp/puppet-systemd/pull/36) ([trevor-vaughan](https://github.com/trevor-vaughan))
**Closed issues:**

- PR\#18 broke service limits capacity [\#35](https://github.com/camptocamp/puppet-systemd/issues/35)
- stdlib functions are used, but no stdlib requirement in metadata.json [\#28](https://github.com/camptocamp/puppet-systemd/issues/28)
- investigate update to camptocamp/systemd module [\#21](https://github.com/camptocamp/puppet-systemd/issues/21)
- Module should be updated to use the new Puppet 4 goodness [\#17](https://github.com/camptocamp/puppet-systemd/issues/17)

**Merged pull requests:**

- Add support for drop-in files [\#39](https://github.com/camptocamp/puppet-systemd/pull/39) ([countsudoku](https://github.com/countsudoku))
- Adds control group limits to ServiceLimits [\#36](https://github.com/camptocamp/puppet-systemd/pull/36) ([trevor-vaughan](https://github.com/trevor-vaughan))
- it's systemd not SystemD [\#33](https://github.com/camptocamp/puppet-systemd/pull/33) ([shibumi](https://github.com/shibumi))
- General cleanup + add Puppet4 datatypes [\#32](https://github.com/camptocamp/puppet-systemd/pull/32) ([bastelfreak](https://github.com/bastelfreak))
- add management for systemd-resolved [\#31](https://github.com/camptocamp/puppet-systemd/pull/31) ([bastelfreak](https://github.com/bastelfreak))
- Add a network defined resource [\#30](https://github.com/camptocamp/puppet-systemd/pull/30) ([bastelfreak](https://github.com/bastelfreak))
- Add seltype to systemd directory [\#27](https://github.com/camptocamp/puppet-systemd/pull/27) ([petems](https://github.com/petems))
- Add MemoryLimit to limits template [\#23](https://github.com/camptocamp/puppet-systemd/pull/23) ([pkilambi](https://github.com/pkilambi))
- Update to support Puppet 4 [\#18](https://github.com/camptocamp/puppet-systemd/pull/18) ([trevor-vaughan](https://github.com/trevor-vaughan))
- Manage resource limits of services [\#13](https://github.com/camptocamp/puppet-systemd/pull/13) ([ruriky](https://github.com/ruriky))
- Refactor systemd facts [\#12](https://github.com/camptocamp/puppet-systemd/pull/12) ([petems](https://github.com/petems))

## [0.4.0](https://github.com/camptocamp/puppet-systemd/tree/0.4.0) (2016-08-18)

## [0.4.0](https://forge.puppetlabs.com/camptocamp/systemd/0.4.0) (2016-08-18)
[Full Changelog](https://github.com/camptocamp/puppet-systemd/compare/0.3.0...0.4.0)

- Deprecate Ruby 1.8 tests
- Only use awk instead of grep and awk [\#9](https://github.com/camptocamp/puppet-systemd/pull/9) ([igalic](https://github.com/igalic))
- Add LICENSE (fix #11)
**Closed issues:**

- No LICENSE file [\#11](https://github.com/camptocamp/puppet-systemd/issues/11)
- Forge update [\#7](https://github.com/camptocamp/puppet-systemd/issues/7)

**Merged pull requests:**

- Add target param for the unit file [\#10](https://github.com/camptocamp/puppet-systemd/pull/10) ([tampakrap](https://github.com/tampakrap))
- only use awk, instead of grep and awk [\#9](https://github.com/camptocamp/puppet-systemd/pull/9) ([igalic](https://github.com/igalic))

# Change Log

## [0.3.0](https://forge.puppetlabs.com/camptocamp/systemd/0.3.0) (2016-05-16)
[Full Changelog](https://github.com/camptocamp/puppet-systemd/compare/0.2.2...0.3.0)
Expand Down Expand Up @@ -92,4 +127,5 @@
- Confine rspec pinning to ruby 1.8


\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Let this module handle file creation and systemd reloading.
```puppet
::systemd::unit_file { 'foo.service':
source => "puppet:///modules/${module_name}/foo.service",
} ~> service {'foo':
ensure => 'running',
}
```

Expand All @@ -32,8 +34,12 @@ file { '/usr/lib/systemd/system/foo.service':
group => 'root',
mode => '0644',
source => "puppet:///modules/${module_name}/foo.service",
} ~> Class['systemd::systemctl::daemon_reload']
service {'foo':
ensure => 'running',
subscribe => File['/usr/lib/systemd/system/foo.service'],
}
~> Class['systemd::systemctl::daemon_reload']
```

### drop-in files
Expand All @@ -46,6 +52,8 @@ directory creation and systemd reloading:
::systemd::dropin_file { 'foo.conf':
unit => 'foo.service',
source => "puppet:///modules/${module_name}/foo.conf",
} ~> service {'foo':
ensure => 'running',
}
```

Expand All @@ -59,14 +67,19 @@ file { '/etc/systemd/system/foo.service.d':
owner => 'root',
group => 'root',
}
file { '/etc/systemd/system/foo.service.d/foo.conf':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => "puppet:///modules/${module_name}/foo.conf",
} ~> Class['systemd::systemctl::daemon_reload']
service {'foo':
ensure => 'running',
subscribe => File['/etc/systemd/system/foo.service.d/foo.conf'],
}
~> Class['systemd::systemctl::daemon_reload']
```

### tmpfiles
Expand Down Expand Up @@ -101,8 +114,8 @@ Manage soft and hard limits on various resources for executed processes.
```puppet
::systemd::service_limits { 'foo.service':
limits => {
LimitNOFILE => 8192,
LimitNPROC => 16384,
'LimitNOFILE' => 8192,
'LimitNPROC' => 16384,
}
}
```
Expand Down Expand Up @@ -131,15 +144,28 @@ for you:

### Services

Systemd provides multiple services. Currently you can manage `systemd-resolved`
and `systemd-networkd` via the main class:
Systemd provides multiple services. Currently you can manage `systemd-resolved`,
`systemd-timesyncd` and `systemd-networkd` via the main class:

```puppet
class{'::systemd':
$manage_resolved => true,
$manage_networkd => true,
$manage_resolved => true,
$manage_networkd => true,
$manage_timesyncd => true,
```

$manage_networkd is required if you want to reload it for new
`::systemd::network` resources. Setting $manage_resolved will also manage your
`/etc/resolv.conf`.

It is possible to configure the default ntp servers in /etc/systemd/timesyncd.conf:

```puppet
class{'::systemd':
$manage_timesyncd => true,
$ntp_server => '0.pool.ntp.org,1.pool.ntp.org',
$fallback_ntp_server => '2.pool.ntp.org,3.pool.ntp.org',
}
```

This requires puppetlabs-inifile, which is only a soft dependency in this module (you need to explicitly install it). Both parameters accept a string or an array.
31 changes: 27 additions & 4 deletions lib/facter/systemd.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fact: systemd
#
# Purpose:
# Purpose:
# Determine whether systemd is the init system on the node
#
# Resolution:
Expand All @@ -9,9 +9,9 @@
# Caveats:
#

# Fact: systemd-version
# Fact: systemd_version
#
# Purpose:
# Purpose:
# Determine the version of systemd installed
#
# Resolution:
Expand All @@ -20,10 +20,20 @@
# Caveats:
#

# Fact: systemd_internal_services
#
# Purpose:
# List all systemd internal real services + their state
#
# Resolution:
# Check the output of systemctl --version
#
# Caveats:
#
Facter.add(:systemd) do
confine :kernel => :linux
setcode do
Facter::Util::Resolution.exec('ps -p 1 -o comm=') == 'systemd'
Facter.value(:service_provider) == 'systemd'
end
end

Expand All @@ -33,3 +43,16 @@
Facter::Util::Resolution.exec("systemctl --version | awk '/systemd/{ print $2 }'")
end
end

Facter.add(:systemd_internal_services) do
confine :systemd => true
setcode do
command_output = Facter::Util::Resolution.exec(
'systemctl list-unit-files --no-legend --no-pager "systemd-*" -t service --state=enabled,disabled,enabled-runtime,indirect'
)
lines = command_output.lines.lazy.map { |line| line.split(/\s+/) }
lines.each_with_object({}) do |(service, status, *), result|
result[service] = status.to_sym
end
end
end
36 changes: 29 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,30 @@
# @param networkd_ensure
# The state that the ``networkd`` service should be in
#
# @param manage_timesyncd
# Manage the systemd tiemsyncd daemon
#
# @param timesyncd_ensure
# The state that the ``timesyncd`` service should be in
#
# @param $ntp_server
# comma separated list of ntp servers, will be combined with interface specific
# addresses from systemd-networkd. requires puppetlabs-inifile
#
# @param fallback_ntp_server
# A space-separated list of NTP server host names or IP addresses to be used
# as the fallback NTP servers. Any per-interface NTP servers obtained from
# systemd-networkd take precedence over this setting. requires puppetlabs-inifile
class systemd (
Optional[Systemd::ServiceLimits] $service_limits = undef,
Boolean $manage_resolved = false,
Enum['stopped','running'] $resolved_ensure = 'running',
Boolean $manage_networkd = false,
Enum['stopped','running'] $networkd_ensure = 'running',
Optional[Systemd::ServiceLimits] $service_limits = undef,
Boolean $manage_resolved = false,
Enum['stopped','running'] $resolved_ensure = 'running',
Boolean $manage_networkd = false,
Enum['stopped','running'] $networkd_ensure = 'running',
Boolean $manage_timesyncd = false,
Enum['stopped','running'] $timesyncd_ensure = 'running',
Optional[String] $ntp_server = undef,
Optional[String] $fallback_ntp_server = undef,
){

contain ::systemd::systemctl::daemon_reload
Expand All @@ -32,11 +50,15 @@
create_resources('systemd::service_limits', $service_limits)
}

if $manage_resolved {
if $manage_resolved and $facts['systemd_internal_services'] and $facts['systemd_internal_services']['systemd-resolved.service'] {
contain ::systemd::resolved
}

if $manage_networkd {
if $manage_networkd and $facts['systemd_internal_services'] and $facts['systemd_internal_services']['systemd-networkd.service'] {
contain ::systemd::networkd
}

if $manage_timesyncd and $facts['systemd_internal_services'] and $facts['systemd_internal_services']['systemd-timesyncd.service'] {
contain ::systemd::timesyncd
}
}
4 changes: 2 additions & 2 deletions manifests/networkd.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# **NOTE: THIS IS A [PRIVATE](https://github.com/puppetlabs/puppetlabs-stdlib#assert_private) CLASS**
#
# This class provides an abstract way to trigger resolved
# This class provides an abstract way to trigger systemd-networkd
#
# @param ensure
# The state that the ``networkd`` service should be in
#
class systemd::networkd (
Enum['stopped','running'] $ensure = 'running',
Enum['stopped','running'] $ensure = $systemd::networkd_ensure,
){

assert_private()
Expand Down
2 changes: 1 addition & 1 deletion manifests/resolved.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The state that the ``resolved`` service should be in
#
class systemd::resolved (
Enum['stopped','running'] $ensure = $::systemd::resolved_ensure,
Enum['stopped','running'] $ensure = $systemd::resolved_ensure,
){

assert_private()
Expand Down
66 changes: 66 additions & 0 deletions manifests/timesyncd.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# **NOTE: THIS IS A [PRIVATE](https://github.com/puppetlabs/puppetlabs-stdlib#assert_private) CLASS**
#
# This class provides an abstract way to trigger systemd-timesyncd
#
# @param ensure
# The state that the ``networkd`` service should be in
#
# @param $ntp_server
# comma separated list of ntp servers, will be combined with interface specific
# addresses from systemd-networkd. requires puppetlabs-inifile
#
# @param fallback_ntp_server
# A space-separated list of NTP server host names or IP addresses to be used
# as the fallback NTP servers. Any per-interface NTP servers obtained from
# systemd-networkd take precedence over this setting. requires puppetlabs-inifile
class systemd::timesyncd (
Enum['stopped','running'] $ensure = $systemd::timesyncd_ensure,
Optional[Variant[Array,String]] $ntp_server = $systemd::ntp_server,
Optional[Variant[Array,String]] $fallback_ntp_server = $systemd::fallback_ntp_server,
){

assert_private()

$_enable_timesyncd = $ensure ? {
'stopped' => false,
'running' => true,
default => $ensure,
}

service{ 'systemd-timesyncd':
ensure => $ensure,
enable => $_enable_timesyncd,
}

if $ntp_server {
if $ntp_server =~ String {
$_ntp_server = $ntp_server
} else {
$_ntp_server = join($ntp_server, ',')
}
ini_setting{'ntp_server':
ensure => 'present',
value => $_ntp_server,
setting => 'NTP',
section => 'Time',
path => '/etc/systemd/timesyncd.conf',
notify => Service['systemd-timesyncd'],
}
}

if $fallback_ntp_server {
if $fallback_ntp_server =~ String {
$_fallback_ntp_server = $fallback_ntp_server
} else {
$_fallback_ntp_server = join($fallback_ntp_server, ',')
}
ini_setting{'fallback_ntp_server':
ensure => 'present',
value => $_fallback_ntp_server,
setting => 'FallbackNTP',
section => 'Time',
path => '/etc/systemd/timesyncd.conf',
notify => Service['systemd-timesyncd'],
}
}
}
Loading