Defined Type: service_autorestart::systemd

Defined in:
manifests/systemd.pp

Summary

Manages the auto-restart (aka service recovery) for a SystemD service.

Overview

Examples:

Basic usage

service_autorestart::systemd { 'puppet': }

Customize the delay between restarts

service_autorestart::systemd { 'puppet':
  delay => '90s',
}

Customize the path and when action restarts

service_autorestart::systemd { 'puppet':
  path  => '/usr/local/lib/systemd/system/puppet.service',
  value => 'on-abort',
  delay => '90s',
}

Disable auto-notify relationships

service_autorestart::systemd { 'puppet':
  autonotify_path                    => false,
  autonotify_systemctl_daemon_reload => false,
}

Parameters:

  • path (String) (defaults to: "${systemd_dir}/${title}.service")

    Path to the systemd service file for this service

  • value (String) (defaults to: 'on-failure')

    The value of the ‘Reset=` setting for the SystemD service. www.freedesktop.org/software/systemd/man/systemd.service.html#Restart=

  • delay (Optional[String]) (defaults to: undef)

    The value of the ‘ResetSec=` setting for the SystemD service. www.freedesktop.org/software/systemd/man/systemd.service.html#RestartSec=

  • autonotify_path (Boolean) (defaults to: true)

    Flag to enable creating an automatic notify relationship between the File and the Ini settings to modify the Restart parameters. Even if enabled, the relationships are protected with a guard, so if File is not defined the relationship will not be created. This prevents errors in environments where these resources aren’t managed by Puppet

  • autonotify_systemctl_daemon_reload (Boolean) (defaults to: true)

    Flag to enable creating an automatic notify relationship between the ‘systemctl daemon-reload’ command and the Ini settings to modify the Restart parameters. The settings will be applied first and the notify the Class of changes. This is enabled by default but probably only useful if you use the camptocamp/systemd module. Even if enabled, the relationships are protected with a guard, so if Class is not defined the relationship will not be created. This prevents errors in environments where these resources aren’t managed by Puppet or the camptocamp/systemd module is not used.

  • systemd_dir (String) (defaults to: lookup('service_autorestart::systemd_dir') |$k| { '/usr/lib/systemd/system' })


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'manifests/systemd.pp', line 53

define service_autorestart::systemd (
  String $systemd_dir  = lookup('service_autorestart::systemd_dir') |$k| { '/usr/lib/systemd/system' },
  String $path  = "${systemd_dir}/${title}.service",
  String $value = 'on-failure',
  Optional[String] $delay = undef,
  Boolean $autonotify_path = true,
  Boolean $autonotify_systemctl_daemon_reload = true
) {
  ini_setting { "systemd_${title}_restart":
    ensure            => present,
    path              => $path,
    section           => 'Service',
    setting           => 'Restart',
    value             => $value,
    key_val_separator => '=',
    tag               => 'service_autorestart',
  }

  if $delay {
    ini_setting { "systemd_${title}_restartsec":
      ensure            => present,
      path              => $path,
      section           => 'Service',
      setting           => 'RestartSec',
      value             => $delay,
      key_val_separator => '=',
      tag               => 'service_autorestart',
    }
  }

  # make sure the file exists before we modify it
  if $autonotify_path and defined(File[$path]) {
    File[$path] ~> Ini_setting<| tag == 'service_autorestart' |>
  }

  # if we're using the camptocamp/systemd module, invoke systemctl daemon_reload
  # so systemd knows about our file changes
  if $autonotify_systemctl_daemon_reload and defined(Class['systemd::systemctl::daemon_reload']) {
    Ini_setting<| tag == 'service_autorestart' |> ~> Class['systemd::systemctl::daemon_reload']
  }
}