Defined Type: systemd::service
- Defined in:
- puppet/modules/systemd/manifests/service.pp
Overview
- template_variables
-
Variables to be exposed to the template. Default: {} Only works for epp templates (see below). Use hiera vars and scope[] for erb.
- epp_template
-
Whether or not the service template is EPP rather than ERB. Default: false
43 44 45 46 47 48 49 50 51 52 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'puppet/modules/systemd/manifests/service.pp', line 43
define systemd::service (
$ensure = 'present',
$is_override = false,
$refresh = true,
$template_name = $name,
$declare_service = true,
$service_params = {},
$template_dir = undef,
$template_variables = {},
$epp_template = false,
) {
validate_ensure($ensure)
if !$template_variables.empty and !$epp_template {
fail("The 'template_variables' option of systemd::service can only be used when 'epp_template' is true")
}
$template_dir_real = $template_dir ? {
undef => "${caller_module_name}/systemd",
default => $template_dir,
}
$unit_template = $epp_template ? {
true => "${template_dir_real}/${template_name}.epp",
default => "${template_dir_real}/${template_name}.erb",
}
$unit_path = $is_override ? {
true => "/etc/systemd/system/${name}.service.d/puppet-override.conf",
default => "/lib/systemd/system/${name}.service",
}
if $is_override {
file { "/etc/systemd/system/${name}.service.d":
ensure => 'directory',
owner => 'root',
group => 'root',
mode => '0555',
before => File[$unit_path],
}
}
$unit_content = $epp_template ? {
true => epp($unit_template, $template_variables),
default => template($unit_template),
}
file { $unit_path:
ensure => $ensure,
owner => 'root',
group => 'root',
mode => '0444',
content => $unit_content,
}
exec { "systemd reload for ${name}":
refreshonly => true,
command => '/bin/systemctl daemon-reload',
subscribe => File[$unit_path],
}
if $declare_service {
if $refresh {
# Notify service of changes to file
File[$unit_path] ~> Service[$name]
} else {
# Ensure that file is applied before the service is called
File[$unit_path] -> Service[$name]
}
# Ensure that systemd reloads before the service is called
Exec["systemd reload for ${name}"] -> Service[$name]
$enable = $ensure ? {
'present' => true,
default => false,
}
$base_params = {
ensure => ensure_service($ensure),
provider => 'systemd',
enable => $enable,
}
$params = merge($base_params, $service_params)
ensure_resource('service', $name, $params)
}
}
|