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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'manifests/systemd/unit_file.pp', line 65
define psick::systemd::unit_file (
Enum['present', 'absent', 'file'] $ensure = 'present',
Stdlib::Absolutepath $path = '/etc/systemd/system',
Optional[Variant[String, Sensitive[String], Deferred]] $content = undef,
Optional[String] $source = undef,
Optional[Stdlib::Absolutepath] $target = undef,
String $owner = 'root',
String $group = 'root',
String $mode = '0444',
Boolean $show_diff = true,
Optional[Variant[Boolean, Enum['mask']]] $enable = undef,
Optional[Boolean] $active = undef,
Optional[String] $restart = undef,
Boolean $selinux_ignore_defaults = false,
Hash[String[1], Any] $service_parameters = {},
) {
include psick::systemd
assert_type(Psick::Systemd::Unit, $name)
if $enable == 'mask' {
$_target = '/dev/null'
} else {
$_target = $target
}
if $_target {
$_ensure = 'link'
} else {
$_ensure = $ensure ? {
'present' => 'file',
default => $ensure,
}
}
file { "${path}/${name}":
ensure => $_ensure,
content => $content,
source => $source,
target => $_target,
owner => $owner,
group => $group,
mode => $mode,
show_diff => $show_diff,
selinux_ignore_defaults => $selinux_ignore_defaults,
}
if $enable != undef or $active != undef {
service { $name:
ensure => $active,
enable => $enable,
restart => $restart,
provider => 'systemd',
* => $service_parameters,
}
if $ensure == 'absent' {
if $enable or $active {
fail("Can't ensure the unit file is absent and activate/enable the service at the same time")
}
Service[$name] -> File["${path}/${name}"]
} else {
File["${path}/${name}"] ~> Service[$name]
}
} else {
# Work around https://tickets.puppetlabs.com/browse/PUP-9473
# and react to changes on static unit files (ie: .service triggered by .timer)
exec { "${name}-systemctl-daemon-reload":
command => 'systemctl daemon-reload',
refreshonly => true,
path => $facts['path'],
subscribe => File["${path}/${name}"],
}
}
}
|