Giter Club home page Giter Club logo

voxpupuli / puppet-systemd Goto Github PK

View Code? Open in Web Editor NEW
52.0 46.0 140.0 1.26 MB

Puppet module to manage systemd

Home Page: https://forge.puppet.com/puppet/systemd

License: Apache License 2.0

Ruby 53.77% Puppet 45.91% Pascal 0.32%
puppet hacktoberfest archlinux-puppet-module centos-puppet-module debian-puppet-module fedora-puppet-module gentoo-puppet-module linux-puppet-module oraclelinux-puppet-module redhat-puppet-module sles-puppet-module ubuntu-puppet-module

puppet-systemd's Introduction

Systemd

Build Status Release Puppet Forge Puppet Forge - downloads Puppet Forge - endorsement Puppet Forge - scores puppetmodule.info docs Apache-2 License Donated by Camptocamp

Overview

This module declares exec resources to create global sync points for reloading systemd.

Version 2 and newer of the module don't work with Hiera 3! You need to migrate your existing Hiera setup to Hiera 5

Usage and examples

There are two ways to use this module.

unit files

Let this module handle file creation.

systemd::unit_file { 'foo.service':
  source => "puppet:///modules/${module_name}/foo.service",
}
~> service { 'foo':
  ensure => 'running',
}

This is equivalent to:

file { '/usr/lib/systemd/system/foo.service':
  ensure => file,
  owner  => 'root',
  group  => 'root',
  mode   => '0644',
  source => "puppet:///modules/${module_name}/foo.service",
}
~> service { 'foo':
  ensure => 'running',
}

You can also use this module to more fully manage the new unit. This example deploys the unit, reloads systemd and then enables and starts it.

systemd::unit_file { 'foo.service':
  content => file("${module_name}/foo.service"),
  enable  => true,
  active  => true,
}

unit files from parameters

Create a unit file from parameters

systemd::manage_unit { 'myrunner.service':
  unit_entry    => {
    'Description' => 'My great service',
  },
  service_entry => {
    'Type'      => 'oneshot',
    'ExecStart' => '/usr/bin/doit.sh',
  },
  install_entry => {
    'WantedBy' => 'multi-user.target',
  },
  enable        => true,
  active        => true,
}

The parameters unit_entry, service_entry and install_entry populate the [Unit], [Service] and [Install] sections of the generated unit file.

Similarly units can be created from hiera yaml files

systemd::manage_units:
  myservice.service:
    unit_entry:
      Description: My Customisation
    service_entry:
      CPUWeight: 2000

drop-in files

Drop-in files are used to add or alter settings of a unit without modifying the unit itself. As for the unit files, the module can handle the file and directory creation:

systemd::dropin_file { 'foo.conf':
  unit   => 'foo.service',
  source => "puppet:///modules/${module_name}/foo.conf",
}
~> service { 'foo':
  ensure => 'running',
}

This is equivalent to:

file { '/etc/systemd/system/foo.service.d':
  ensure => directory,
  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",
}
~> service { 'foo':
  ensure => 'running',
}

dropin-files can also be generated via hiera:

systemd::dropin_files:
  my-foo.conf:
    unit: foo.service
    source: puppet:///modules/${module_name}/foo.conf

drop-in files from parameters

systemd::manage_dropin { 'myconf.conf':
  ensure        => present,
  unit          => 'myservice.service',
  service_entry => {
    'Type'      => 'oneshot',
    'ExecStart' => ['', '/usr/bin/doit.sh'],
  },
}

Dropins can also be created similarly via yaml

systemd::manage_dropins:
  myconf.conf:
    ensure: present
    unit: myservice.service
    service_entry:
      Type: oneshot
      ExecStart:
        - ''
        - '/usr/bin/doit.sh'

The filename of the drop in. The full path is determined using the path, unit and this filename.

modules-load.d

Create a file entry for modules-loads directory and start systemd-modules-load.service

systemd::modules_load { 'impi.conf':
  content => "ipmi\n",
}

tmpfiles

Let this module handle file creation and systemd reloading

systemd::tmpfile { 'foo.conf':
  source => "puppet:///modules/${module_name}/foo.conf",
}

Or handle file creation yourself and trigger systemd.

include systemd::tmpfiles

file { '/etc/tmpfiles.d/foo.conf':
  ensure => file,
  owner  => 'root',
  group  => 'root',
  mode   => '0644',
  source => "puppet:///modules/${module_name}/foo.conf",
}
~> Class['systemd::tmpfiles']

timer units

Create a systemd timer unit and a systemd service unit to execute from that timer

The following will create a timer unit and a service unit file. When active and enable are set to true the puppet service runoften.timer will be declared, started and enabled.

systemd::timer { 'runoften.timer':
  timer_source   => "puppet:///modules/${module_name}/runoften.timer",
  service_source => "puppet:///modules/${module_name}/runoften.service",
  active         => true,
  enable         => true,
}

A trivial daily run. In this case enable and active are both unset and so the service daily.timer is not declared by the systemd::timer type.

$_timer = @(EOT)
[Timer]
OnCalendar=daily
RandomizedDelaySec=1d
EOT

$_service = @(EOT)
[Service]
Type=oneshot
ExecStart=/usr/bin/touch /tmp/file
EOT

systemd::timer { 'daily.timer':
  timer_content   => $_timer,
  service_content => $_service,
}

service { 'daily.timer':
  ensure    => running,
  subscribe => Systemd::Timer['daily.timer'],
}

If neither service_content or service_source are specified then no service unit will be created.

The service unit name can also be specified.

$_timer = @(EOT)
[Timer]
OnCalendar=daily
RandomizedDelaySec=1d
Unit=touch-me-today.service
EOT

$_service = @(EOT)
[Service]
Type=oneshot
ExecStart=/usr/bin/touch /tmp/file
EOT

systemd::timer { 'daily.timer':
  timer_content   => $_timer,
  service_unit    => 'touch-me-today.service',
  service_content => $_service,
  active          => true,
  enable          => true,
}

service limits

It's possible to ensure soft and hard limits on various resources for executed processes. Previously systemd::service_limits was provided, but this is deprecated and will be removed in the next version.

systemd::service_limits { 'foo.service':
  limits => {
    'LimitNOFILE' => 8192,
    'LimitNPROC'  => 16384,
  }
}

The replacement is to use the systemd::manage_dropin defined type directly. To migrate from the above example, use the following:

systemd::manage_dropin { 'foo.service-90-limits.conf':
  unit     => 'foo.service',
  filename => '90-limits.conf',
  limits   => {
    'LimitNOFILE' => 8192,
    'LimitNPROC'  => 16384,
  },
}

machine-info (hostnamectl)

You can set elements of /etc/machine-info via the machine_info_settings parameter. These values are read by hostnamectl.

To manage these, you'll need to add an additional module, augeasproviders_shellvar, to your environment.

Daemon reloads

Systemd caches unit files and their relations. This means it needs to reload, typically done via systemctl daemon-reload. Since Puppet 6.1.0 (PUP-3483) takes care of this by calling systemctl show $SERVICE -- --property=NeedDaemonReload to determine if a reload is needed. Typically this works well and removes the need for systemd::systemctl::daemon_reload as provided prior to camptocamp/systemd 3.0.0. This avoids common circular dependencies.

It does contain a workaround for PUP-9473 but there's no guarantee that this works in every case.

network

systemd-networkd is able to manage your network configuration. We provide a defined resource which can write the interface configurations. systemd-networkd needs to be restarted to apply the configs. The defined resource can do this for you:

systemd::network { 'eth0.network':
  source          => "puppet:///modules/${module_name}/eth0.network",
  restart_service => true,
}

Services

The default target is managed via the default_target parameter. If this is left at its default value (undef), the default-target will be unmanaged by puppet.

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

class { 'systemd':
  manage_resolved  => true,
  manage_networkd  => true,
  manage_timesyncd => true,
  manage_journald  => true,
  manage_udevd     => true,
  manage_logind    => true,
  manage_coredump  => 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.

When configuring systemd::resolved you could set use_stub_resolver to false (default) to use a standard /etc/resolved.conf, or you could set it to true to use the local resolver provided by systemd-resolved.

Systemd introduced DNS Over TLS in release 239. Currently three states are supported yes (since systemd 243), opportunistic (true) and no (false, default). When enabled with yes or opportunistic systemd-resolved will start a TCP-session to a DNS server with DNS Over TLS support. When enabled with yes (strict mode), queries will fail if the configured DNS servers do not support DNS Over TLS. Note that there will be no host checking for DNS Over TLS due to missing implementation in systemd-resolved.

Stopping systemd-resolved once running can be problematic and care should be taken.

class { 'systemd':
  manage_resolved => true,
  resolved_ensure => false,
}

will stop the service and should also copy /run/systemd/resolve/resolv.conf to /etc/resolve.conf.

  • Writing your own file to /etc/resolv.conf is also possible.

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

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'],
}

when manage_systemd is true any required sub package, e.g. systemd-resolved on CentOS 9 or Debian 12, will be installed. However configuration of systemd-resolved will only occur on second puppet run after that installation.

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.

Resource Accounting

Systemd has support for different accounting option. It can track CPU/Memory/Network stats per process. This is explained in depth at systemd-system.conf. This defaults to off (default on most operating systems). You can enable this with the $manage_accounting parameter. The module provides a default set of working accounting options per operating system, but you can still modify them with $accounting:

class { 'systemd':
  manage_accounting => true,
  accounting        => {
    'DefaultCPUAccounting'    => 'yes',
    'DefaultMemoryAccounting' => 'no',
  }
}

journald configuration

It also allows you to manage journald settings. You can manage journald settings through setting the journald_settings parameter. If you want a parameter to be removed, you can pass its value as params.

systemd::journald_settings:
  Storage: auto
  MaxRetentionSec: 5day
  MaxLevelStore:
    ensure: absent

udevd configuration

It allows you to manage the udevd configuration. You can set the udev.conf values via the udev_log, udev_children_max, udev_exec_delay, udev_event_timeout, udev_resolve_names, and udev_timeout_signal parameters.

Additionally you can set custom udev rules with the udev_rules parameter.

class { 'systemd':
  manage_udevd => true,
  udev_rules   => {
    'example_raw.rules' => {
      'rules' => [
        'ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"',
        'ACTION=="add", KERNEL=="sdb", RUN+="/bin/raw /dev/raw/raw2 %N"',
      ],
    },
  },
}

udev::rules configuration

Custom udev rules can be defined for specific events.

systemd::udev::rule:
  ensure: present
  path: /etc/udev/rules.d
  selinux_ignore_defaults: false
  notify: "Service[systemd-udevd]"
  rules:
    - 'ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"'
    - 'ACTION=="add", KERNEL=="sdb", RUN+="/bin/raw /dev/raw/raw2 %N"',

oomd configuration

The systemd-oomd system can be configured.

class { 'systemd':
  manage_oomd   => true,
  oomd_ensure   => 'running'
  oomd_settings => {
    'SwapUsedLimit'                    => '90%',
    'DefaultMemoryPressureLimit'       => '60%',
    'DefaultMemoryPressureDurationSec' => 30,
  }
}

coredump configuration

The systemd-coredump system can be configured.

class{'systemd':
  manage_coredump    => true,
  coredump_backtrace => true,
  coredump_settings  => {
    'Storage'         => 'external',
    'Compress'        => 'yes',
    'ProcessSizeMax'  => '2G',
    'ExternalSizeMax' => '10G',
    'JournalSizeMax'  => '20T',
    'MaxUse'          => '1E',
    'KeepFree'        => '1P',
  }
}

logind configuration

It also allows you to manage logind settings. You can manage logind settings through setting the logind_settings parameter. If you want a parameter to be removed, you can pass its value as params.

systemd::logind_settings:
  HandleSuspendKey: 'ignore'
  KillUserProcesses: 'no'
  RemoveIPC:
    ensure: absent
  UserTasksMax: 10000

User linger

A loginctl_user resource is available to manage user linger enablement:

loginctl_user { 'foo':
  linger => enabled,
}

or as a hash via the systemd::loginctl_users parameter.

Systemd Escape Function

Partially escape strings as systemd-escape command does.

This functions only escapes a subset of chars. Non-ASCII character will not escape.

$result = systemd::escape('foo::bar/')

$result would be foo::bar-

or path escape as if with -p option.

$result = systemd::escape('/mnt/foobar/', true)

$result would be mnt-foobar.

Systemd Escape Function (uses systemd-escape)

Escape strings call the systemd-escape command in the background.

It's highly recommend running the function as deferred function since it executes the command on the agent.

$result = Deferred('systemd::systemd_escape', ["foo::bar"])

$result would be foo::bar-

or path escape as if with -p option.

$result = Deferred('systemd::systemd_escape', ["/mnt/foo-bar/", true])

$result would be mnt-foo\x2dbar.

Tasks

systemd::systemctl_show

Returns more parseable output then the standard service task from bolt itself.

Default property filter: ["ActiveState", "LoadState", "MainPID", "SubState", "UnitFileState"]

output of standard task from bolt

bolt task run service name=puppet.service action=status -t controller-0

Started on controller-0...
Finished on controller-0:
  {
    "status": "MainPID=686,LoadState=loaded,ActiveState=active",
    "enabled": "enabled"
  }

output of systemd::systemctl_show

bolt task run systemd::systemctl_show unit_name=puppet.service -t controller-0

Started on controller-0...
Finished on controller-0:
  {
    "MainPID": "686",
    "LoadState": "loaded",
    "ActiveState": "active",
    "SubState": "running",
    "UnitFileState": "enabled"
  }

Deprecation Notices

The type systemd::service_limits is deprecated and systemd::manage_dropin or systemd::dropin_file should be used instead.

Transfer Notice

This plugin was originally authored by Camptocamp. The maintainer preferred that Puppet Community take ownership of the module for future improvement and maintenance. Existing pull requests and issues were transferred over, please fork and continue to contribute here instead of Camptocamp.

Previously: [https://github.com/camptocamp/puppet-systemd]

puppet-systemd's People

Contributors

alexjfisher avatar bastelfreak avatar baurmatt avatar countsudoku avatar ekohl avatar evgeni avatar fragfutter avatar griggi-ws avatar hfm avatar jasonknudsen avatar jcharaoui avatar jcpunk avatar jhoblitt avatar kenyon avatar matt6697 avatar mcanevet avatar petems avatar raphink avatar root-expert avatar rwaffen avatar saimonn avatar schustersv avatar seanhood avatar simondeziel avatar smortex avatar themeier avatar traylenator avatar trevor-vaughan avatar treydock avatar zilchms avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppet-systemd's Issues

Hiera usage for systemd::unit_file

hi,

just a short question: can I call the systemd::unit_file from Hiera too ? I tried was included the systemd class and

systemd::unit_file:
  'foo':
    ensure: 'running'
    source: 'puppet:///...foo.service'

but it seems, that I have to use a create_resource manifest wrapper .., or maybe I just call the class wrong ...

Static units cannot be enabled

Description

systemd version: 219
module version: 2.12.0

definition of worker.target

root@tst-api01 ~ # systemctl cat worker.target
# /etc/systemd/system/worker.target
[Unit]
Description=Queue Workers
Wants=rabbitmq-server.service [email protected] api-default-queue

[Install]
WantedBy=multi-user.target

Definition of api-default-queue.service (instantiated from template) in hiera:

systemd::manage::unit_file:
  [email protected]:
    content: |
      [Unit]
      Description=default-queue-%i
      BindsTo=worker.target

      [Service]
      Type=simple
      ExecStart=FOO
      SyslogIdentifier=default-queue-%i
      Group=FOO
      User=FOO
      Restart=on-failure
      RestartSec=10
      TimeoutStartSec=10
  [email protected]:
    enable: true
    active: true

Expected behaviour:

Puppet tries to enables that unit but realizes that it's a static unit and does nothing.

Actual behaviour

Puppet restarts the unit

Debug: Executing: '/bin/systemctl is-enabled -- [email protected]'
Debug: Executing: '/bin/systemctl unmask -- [email protected]'
Debug: Executing: '/bin/systemctl enable -- [email protected]'
Debug: Executing: '/bin/systemctl is-enabled -- [email protected]'
Debug: Unable to enable or disable static service [email protected]
Notice: /Stage[main]/Systemd::Manage/Systemd::Unit_file[[email protected]]/Service[[email protected]]/enable: enable changed 'false' to 'true'

leads to

Feb 20 19:18:28 prd-api01 systemd[1]: Stopped api-default-queue-1.
Feb 20 19:18:28 prd-api01 systemd[1]: Started api-default-queue-1.

Suggested behaviour:

It's eventually a clash of responsibilites between systemd and puppet. Meaning: "who is, in the end, reponsible for managing the state of that unit". With harder dependencies, it seems to rather be within system`s jurisdiction, on the other hand though, when there are no hard bindings between units, it makes sense for puppet to manage that unit.

Since it obviously does not make sense for the module to try to understand the interdependency between defined units (in order to not allow enable: true for static units), I'd suggest that this module accepts "static" as a valid return-value (instead of only "enable" now, probably - not verified) for systemctl is-enabled $UNIT.

Not able to set limits via systemd class

I want to setup some systemd limits for a service so I have included ...

    include ::systemd

... in my manifest. And I have this hiera data:

systemd::service_limits:
    'openstack-nova-compute.service':
        limits:
                LimitNOFILE: 32768

But when puppet on my node I get this error:

Error while evaluating a Function Call, Class[Systemd]: parameter 'service_limits' unrecognized key 'openstack-nova-compute.service' at ...

I have looked at the docs and they do not explain how to form the hash in hiera, they just give this example:

::systemd::service_limits { 'foo.service':
  limits => {
    'LimitNOFILE' => 8192,
    'LimitNPROC'  => 16384,
  }
}

So how would I do that in hiera/yaml?

LimitNOFILE restricted to integer type

Hi, why is LimitNOFILE an integer type? AFAIK infinity can be used with LimitNOFILE on systemd.
Should not be this more appropriate?

    Optional['LimitNOFILE']         => Pattern['^(infinity|(\d+)$'],

Custom SystemD Unit File will be created, but its not define in Puppet hiera

Hello,
i've following issue (Module Version 2.10):

In Hiera, i've the following Statement:

systemd::timer { 'mlocate-updatedb.timer':
active => true,
enable => true,
}

By a Puppet Run, he will created a Custom Timer File:

Notice: /Stage[main]/Profile::Linux::Rhel8/Systemd::Timer[mlocate-updatedb.timer]/Systemd::Unit_file[mlocate-updatedb.timer]/File[/etc/systemd/system/mlocate-updatedb.timer]/ensure: created (corrective)

But i've no Parameter like "service_content or service_source" defined and according to the Doku , the Default Value for both are "undefined". So i expect that he doesnt create a custom systemd Unit File.

It this a bug ?

Regards
Oliver

Add capability to manage /etc/systemd/*.conf files

While this module does give you the capability to configure some systemd configurations (eg. /etc/systemd/logind.conf), it would be nice if it was able to configure the other configurables available (eg. /etc/systemd/networkd.conf).

I don't know if a generic mechanism would be the way to approach that, or to have specific entry points into the different config files and track them over time, adding them as they appear in systemd versions.

At the moment I see on my system journald.conf, logind.conf, networkd.conf, pstore.conf, resolved.conf, sleep.conf, system.conf, timesyncd.conf, and user.conf.

add timer support

systemd provides a cron-like system replacement, through the use of unit configuration files that end in ".timer". These unit configurations encode information about timers controlled and supervised by systemd, for timer-based activation.

It would be excellent if this module provided a mechanism for managing these!

Puppet version compatibility

Hello puppet-systemd,
I just found that the metadata file contains incorrect information about the puppet version compatibility.
For instance, it claims it is compatible with versions < 3.7 . However the parametrized arguments in init.pp do not agree.
Is it possible to have a cleaned up version of metadata file ?

Regards.

Cyclic dependency error when using systemd::unit_file in multiple classes

Using systemd::unit_file in multiple, strictly ordered classes, causes a cyclic dependency error.

Consider the following code:

  1. Role:
class role::base {
  contain profile::systemd
  contain profile::base_os
  contain profile::monitoring

  Class['profile::systemd']
  -> Class['profile::base_os']
  -> Class['profile::monitoring']
}
  1. Profiles
    2.1. profile::systemd
class profile::systemd {
  class { 'systemd':
    manage_resolved => false,
    manage_networkd => false,
  }
}

2.2. profie::base_os

class profile::base_os {
  systemd::unit_file { 'remove_check_mk_cache.service':
    content => file('profile/remove_checkmk_cache.service'),
    active  => true,
    notify  => Service['remove_check_mk_cache'],
  }
  service { 'remove_check_mk_cache':
    ensure => running,
    enable => true,
    require => Class['systemd::systemctl::daemon_reload'],
  }
}

2.3. profile::monitoring

class profile::monitoring {
  systemd::unit_file { 'send_downtime.service':
    content => file('profile/send_downtime.service'),
    active  => true,
    notify  => Service['send_downtime'],
  }
  service { 'send_downtime':
    ensure => running,
    enable => true,
    require => Class['systemd::systemctl::daemon_reload'],
  }
}

Unit tests or using this code on a system produce cyclic dependency error:

role::base on centos-7-x86_64 is expected to compile into a catalogue without dependency cycles
     Failure/Error: it { is_expected.to compile }
       dependency cycles found: (Exec[systemctl-daemon-reload] => Class[Systemd::Systemctl::Daemon_reload] => Service[remove_check_mk_cache] => Class[Profile::Base_os] => Class[Profile::Monitoring] => Systemd::Unit_file[send_downtime.service] => File[/etc/systemd/system/send_downtime.service] => Class[Systemd::Systemctl::Daemon_reload] => Exec[systemctl-daemon-reload])
     # ./spec/classes/base_spec.rb:10:in `block (4 levels) in <top (required)>'

How to enable/start parameterized timers?

If I'm not mistaken there currently is no support for parameterized timer units, at least I have not found a way to model the result of these commands with the module:

systemctl enable borgwrapper-backup@<config_name>.timer
systemctl start borgwrapper-backup@<config_name>.timer

Could this be added or the documentation improved if this is already supported?

Please revert Puppet 5 dropping patch

Hi,

In this commit:
97dd16f

you are dropping puppet 5 support. Unfortunately, in Debian, we were not able to package Puppet 6, due to some problems packaging jruby. So Bullseye will continue to contain Puppet 5. Therefore, I would like to kindly ask you to continue to support us for at least the following 2 to 3 years.

Cheers,

Thomas Goirand (zigo)

Add explicit ordering to README.md

It would be helpful if the README file had a complete example containing both a systemd::unit_file and a service resource. In particular, it wasn't immediately obvious that the ordering needs to be made explicit:

::systemd::unit_file { 'foo.service':
 source => "puppet:///modules/${module_name}/foo.service",
}

service { foo:
  enable  => true,
  ensure  => running,
  require => Systemd::Unit_file['foo.service']
}

Without the explicit ordering, Puppet will attempt to start the service before the unit file has been created.

fact systemd_internal_services is empty

puppet facts throws a warning:

Facter: Fact resolution fact='systemd_internal_services', resolution='' resolved to an invalid value: Expected disabled to be one of [Integer, Float, TrueClass, FalseClass, NilClass, String, Array, Hash], but was Symbol

And there was no fact "systemd_internal_services"

Removing .to_sym from result[service] = status.to_sym in /lib/facter/systemd.rb (line 55) fixed it for me.

Cache cannot be set to no in /etc/systemd/resolved.conf

As far as I understand one should be able to set the value of Cache to 'yes' or 'no' in /etc/systemd/resolved.conf via systemd::resolved.

But in systemd::resolved the variable named $cache is a Boolean and if it is set to false, the value does not get rendered to /etc/systemd/resolved.conf:

$_cache = $cache ? {
    true    => 'yes',
    false   => 'no',
  }

  if $cache {
    ini_setting{ 'cache':
      ensure  => 'present',
      value   => $_cache,
      setting => 'Cache',
      section => 'Resolve',
      path    => '/etc/systemd/resolved.conf',
      notify  => Service['systemd-resolved'],
    }
  }

So only setting it to true will render it to the file with Cache=yes (which under Ubuntu is the default anyway) and one can never set Cache=no. Because using only a Boolean will mean you have to render it out everywhere (even on installations where you are not concerned with this value and would like not to have this file modified), I would hope for a different solution (e.g. not using a Boolean or two variables).

Thank you so much!

daemon reload problem with 3.0.0

After updating to 3.0.0 limits configuration seems to be broken.
In the manifest I have:

systemd::service_limits { 'php7.4-fpm.service':
  limits => {
    'LimitNOFILE' => 1048576,
  }
}

Puppet applied this code and tried to perform service restart:
Exec[restart php7.4-fpm.service because limits]

But in fact, new limits were not applied, because of lack of daemon reload. By code I see there is call of:
systemctl restart php7.4-fpm.service

By running it by hand after puppet run, I got:

~# systemctl restart php7.4-fpm.service
Warning: The unit file, source configuration file or drop-ins of php7.4-fpm.service changed on disk. Run 'systemctl daemon-reload' to reload units.

So, I need to reload daemon manually, and then restart the service.

OS Debian 10.9
Puppet server 7.1.0
Puppet agent 7.5.0

This module is not indempotent

Due to systemd design, this module is not indempotent.

The problem

include ::systemd
file { '/usr/lib/systemd/system/foo.service':
  ensure => file,
  owner  => 'root',
  group  => 'root',
  mode   => '0644',
  source => "puppet:///modules/${module_name}/foo.service",
} ~>
Exec['systemctl-daemon-reload']

service{
  'foo':
    ensure => started,
    subscribe => File['/usr/lib/systemd/system/foo.service']
    require => Exec['systemctl-daemon-reload']
  }
}

file { '/usr/lib/systemd/system/foo2.service':
  ensure => file,
  owner  => 'root',
  group  => 'xyz',
  mode   => '0644',
} ~>
Exec['systemctl-daemon-reload']

First run:

  • File[foo.service] is changed
  • File[foo2.service] file fails during catalog execution (imagine that group xyz does not exist)
  • Exec['systemctl-daemon-reload'] is not called because File[foo2] failed
  • Service[foo] is not restarted because Exec['systemctl-daemon-reload'] is skipped

Fix File[foo2.service].

Second run:

  • File[foo.service] is not changed
  • File[foo2.service] file is changed
  • Exec['systemctl-daemon-reload'] istriggered
  • Service[foo] is not restarted because File[foo.service]has not been changed uring this run.

Proposal

Use Defines instead of classee

file { '/usr/lib/systemd/system/foo.service':
  ensure => file,
  owner  => 'root',
  group  => 'root',
  mode   => '0644',
  source => "puppet:///modules/${module_name}/foo.service",
} ~>
systemd::daemonreload{
  'foo.service':
}

service{
  'foo':
    ensure => started,
    subscribe => File['/usr/lib/systemd/system/foo.service']
    require => Systemd::Daemonreload['foo']
  }
}

file { '/usr/lib/systemd/system/foo2.service':
  ensure => file,
  owner  => 'root',
  group  => 'root',
  mode   => '0644',
  source => "NONEXISTANT",
} ~>
systemd::daemonreload{
  'foo2.service':
}
Upides of proposal

It makes the module indempotent if used as described here.

Downsides

calling systemd daemon-reload is blocking and may cause problems in very large systems.

Mitigation: Use only one reload.

Backwards compatibility: Offer a class which contains systemd::daemonreload {'generic':}

TODO

  • Collect some comments
  • Implement the define
  • Implement backward compatibility
  • Document that in README

migration path drop in file from 0.4.0 to 1.0.0

while its great to see that there is now a type for drop ins i am missing a migration path from handling drop-in file with systemd::unit_file.
if i ugrade from 0.x to 1.x have to change all of my modules using something like this

systemd::unit_file{'myserviceservice.d/10-disable.conf':
   ...

at the same time. otherwise my code breaks at assert_type(Systemd::Unit, $name)

stdlib functions are used, but no stdlib requirement in metadata.json

Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Unknown function: 'validate_hash'. at /etc/puppetlabs/code/environments/production/modules/systemd/manifests/service_limits.pp:13:5 at /etc/puppetlabs/code/environments/production/modules/systemd/foo.pp:1 on node localhost.localdomain

No LICENSE file

Would you be willing to mark this code as released under a specific OSI license? That would make using it in a corporate setting easier. Thanks.

Better test for systemd (and other init systems)

The recommended test for init=systemd fails on systems where the init binary is named "/sbin/init" rather than "systemd".

The following test works on every system I've tried so far:

/proc/1/exe --version | grep -q 'systemd'

README refers to non-existent dns_stub_resolver parameter

The README currently says:

When configuring systemd::resolved you could set dns_stub_resolver to false (default) to use a standard /etc/resolved.conf, or you could set it to true to use the local resolver provided by systemd-resolved.

But the dns_stub_resolver parameter doesn't exist anywhere. There are dns_stub_listener and use_stub_resolver in systemd::resolved but neither do what is described above (which is, i guess, to leave resolv.conf alone?)

Anyways, this is rather all unclear and i suspect it should instead document whatever it is that use_stub_resolver does, but even that is not quite clear to me. :)

STIG Rule RHEL-07-021340 - The system must use a separate file system for /tmp

Red Hat Enterprise Linux 7 Security Technical Implementation Guide
Release: 4
Benchmark Date: 26 Jan 2018
Vuln ID: V-72065
Rule ID: SV-86689r1_rule
STIG ID: RHEL-07-021340

Check Text: Verify that a separate file system/partition has been created for "/tmp".
Check that a file system/partition has been created for "/tmp" with the following command:
# systemctl is-enabled tmp.mount
enabled
If the "tmp.mount" service is not enabled, this is a finding.
Fix Text: Start the "tmp.mount" service with the following command:
# systemctl enable tmp.mount

It is not obvious if the module will do this, but I am going to give it a try

Force ordering on systemd daemon reload before service restart

Hello,

The readme gives the following example:

include systemd::systemctl::daemon_reload

file { '/usr/lib/systemd/system/foo.service':
  ensure => file,
  owner  => 'root',
  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'],
}

But from what I know, this won't force the daemon reload to happen before the service 'foo' is refreshed. Instead, it should be safer to have it explicitly set with a require:

service { 'foo':
  ensure    => 'running',
  subscribe => File['/usr/lib/systemd/system/foo.service'],
  require   => Class['systemd::systemctl::daemon_reload'],
}

Please let me know if I'm wrong here.

'systemctl daemon-reload' is not qualified

When importing this module and then running spec tests I get the following:

Failure/Error: it { should compile.with_all_deps }
  error during compilation: Validation of Exec[systemctl-daemon-reload] failed: 'systemctl daemon-reload' is not qualified and no path was specified. Please qualify the command or specify a path. at /mnt/spec/fixtures/modules/systemd/manifests/init.pp:11

The fix appears to be to change:

  Exec {
    refreshonly => true,
    path        => $::path,
  }

to:

  Exec {
    refreshonly => true,
    path        => split($::path, ':'),
  }

Not sure if this breaks other things though.

Allow service reloading

There is no easy way to use
systemctl reload <service>
for a specified service. Puppet will always restart it.

I suggest adding some parameter like $use_reload to systemd::unit_file that will set the restart argument of service.

Add support for user-based Systemd resources

One of the benefits to Systemd is spawning a Systemd user instance where a user can edit, start, and stop their own services, timers, etc. without requiring permissions to the system-level resources.

While I understand that managing user configurations with Puppet is not advisable, It would be nice to manage the global Systemd user units for secured systems. For services, this means that any user that logs in, a service is started under their Systemd instance and will continue to run until the user logs out.

It is my understanding that the Puppet service resource does not support user-based services. I believe any implementation this the above use-cases would require an exec resource to enable or disable them.

Standalone User Service

Path: ~/.config/systemd/user/example.service
Command: systemctl --user enable example.service (as user)

Global User Service

Path: /etc/systemd/user/example.service
Command: systemctl --user --global enable example.service (as root)

References

Manage drop-in files

Can support for drop-in files to override package units be added to this module?

Discussion: use class instead of exec for notification

I think it would make more sense to use this module like this:

file { '/lib/systemd/system/my.service':
   [...]
} ~> Class[Systemd::DaemonReload]

Reasons I can think of:

  • make code be easier to modify without changing interface
  • make code more portable: one dist may need executing something, the other noop

vacuum as routine task

I would like to clean up entries older than n days.
A cleanup option $vacuum_time='35d' which results in a daily cron entry

journalctl --vacuum-time=35d 

would be fine.
One could consider --vacuum-size and --vacuum-files, too.

systemd-resolved cannot be fully disabled because /etc/resolv.conf is managed

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: all
  • Ruby: all
  • Distribution: Ubuntu 20.04 (client)
  • Module version: 3.0.0, 3.1.0

How to reproduce (e.g Puppet code you use)

class demo {
  class { 'systemd':
    manage_resolved => true,
    resolved_ensure => 'stopped',
  }

  file { '/etc/resolv.conf':
    ensure => 'file',
  }
}

What are you seeing

Catalog compilation fails with with a duplicate resource declaration error.

What behaviour did you expect instead

File[/etc/resolv.conf] should not be managed when systemd-resolved is managed to the stopped state.

Output log

Duplicate declaration: File[/etc/resolv.conf] is already declared at (.../modules/systemd/manifests/resolved.pp, line: 77); cannot redeclare (.../modules/demo/manifests/init.pp, line: 7) (file: .../modules/demo/spec/fixtures/modules/demo/manifests/init.pp, line: 7, column: 3) on node ...

Any additional information you'd like to impart

Just stopping systemd-resolved on a system that has had it configured completely breaks name resolution. Something else needs to manage /etc/resolv.conf afterward, or at least to update it once, but the module interferes with that.

For context, on domain-joined Ubuntu 20.04, systemd-resolved needs to be disabled in order for sssd to authenticate users against Active Directory.

Here is the RSpec test used to demonstrate the issue:

# frozen_string_literal: true

require 'spec_helper'

describe 'demo' do
  on_supported_os.each do |os, os_facts|
    context "on #{os}" do
      let(:facts) { os_facts.merge(systemd_internal_services: { 'systemd-resolved.service' => 'enabled' }) }

      it { is_expected.to compile }
    end
  end
end

Forge update

Should be great if one could publish a new version to the forge

Grts and Thx

Johan

Flapping $::path forces to persist a new catalog into PuppetDB

Hi,

When running Puppet interactively the value of $::path might differ from background runs as the former is taken from the login shell. This generates a catalog diff that perhaps will not apply any change on the target system but it will force a catalog replacement on PuppetDB which is kind of unnecessary IMHO.

I, [2018-02-27T09:38:52.953787 #3195]  INFO -- : Catalogs compiled for foo.example.com
I, [2018-02-27T09:38:54.314022 #3195]  INFO -- : Diffs computed for foo.example.com
  Exec[systemctl-daemon-reload] =>
   parameters =>
     path =>
      - /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin
      + /usr/sue/sbin:/usr/sue/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/puppetlabs/bin:/root/bin:/sbin

https://github.com/camptocamp/puppet-systemd/blob/20a465b0d8751bc08913b556d0a5b7fdac139271/manifests/systemctl/daemon_reload.pp#L8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.