Defined Type: systemd_cron
- Defined in:
- manifests/init.pp
Overview
systemd_cron Create systemd timer/service to replace cron jobs You either need to define on_calendar or on_boot_sec
33 34 35 36 37 38 39 40 41 42 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 |
# File 'manifests/init.pp', line 33
define systemd_cron (
String $command,
String $service_description,
Optional[String] $on_calendar = undef,
Optional[Variant[Integer,String]] $on_boot_sec = undef,
Optional[Variant[Integer,String]] $on_unitactive_sec = undef,
String $timer_description = "timer for ${service_description}",
Variant[Boolean,Enum['present','absent']] $ensure = true,
String $type = 'oneshot',
String $user = 'root',
Optional[Array] $additional_timer_params = undef,
Optional[Array] $additional_service_params = undef,
) {
if ! $on_calendar and ! $on_boot_sec {
fail("systemd_cron['${title}']: you need to define on_calendar or on_boot_sec")
}
$file_ensure = $ensure ? {
false => 'absent',
'absent' => 'absent',
default => 'present'
}
$service_ensure = $ensure ? {
false => false,
'absent' => false,
default => true,
}
$unit_name = regsubst($title, '/' , '_', 'G')
systemd::unit_file { "${unit_name}_cron.service":
ensure => $file_ensure,
content => epp('systemd_cron/service.epp', {
'description' => $service_description,
'command' => $command,
'user' => $user,
'type' => $type,
'additional_params' => $additional_service_params,
}
),
}
systemd::unit_file { "${unit_name}_cron.timer":
ensure => $file_ensure,
content => epp('systemd_cron/timer.epp', {
'description' => $timer_description,
'on_calendar' => $on_calendar,
'on_boot_sec' => $on_boot_sec,
'on_unitactive_sec' => $on_unitactive_sec,
'additional_params' => $additional_timer_params,
}
),
}
service { "${unit_name}_cron.timer":
ensure => $service_ensure,
enable => $service_ensure,
}
if $service_ensure {
Systemd::Unit_file["${unit_name}_cron.service"] -> Systemd::Unit_file["${unit_name}_cron.timer"] -> Service["${unit_name}_cron.timer"]
} else {
Service["${unit_name}_cron.timer"] -> Systemd::Unit_file["${unit_name}_cron.timer"] -> Systemd::Unit_file["${unit_name}_cron.service"]
}
}
|