Add systemd units to manage updater

This commit is contained in:
Antonio J. Delgado 2024-02-16 15:24:38 +02:00
parent 4bcc226c4b
commit 0f5e6de312

View file

@ -60,6 +60,12 @@
# [*nodejs_version*] # [*nodejs_version*]
# String with nodejs version to install. Default 16.x # String with nodejs version to install. Default 16.x
# #
# [*manage_updater_task*]
# Boolean indicating if this class should manage a scheduled task (Systemd Timer unit) to update Mastodon automatically. Requires a github token with read access to public repos.
#
# [*github_token*]
# String with the Github token with read access to public repos.
#
class mastodon ( class mastodon (
String $ensure = 'present', String $ensure = 'present',
String $hostname = 'mastodon.example.org', String $hostname = 'mastodon.example.org',
@ -102,6 +108,8 @@ class mastodon (
}, },
Array $users = [], Array $users = [],
String $cert_admin_mail = 'cert-admin@example.org', String $cert_admin_mail = 'cert-admin@example.org',
Boolean $manage_updater_task = false,
String $github_token = '',
) { ) {
case $ensure { case $ensure {
default: { default: {
@ -547,4 +555,38 @@ class mastodon (
active => true, active => true,
enable => true, enable => true,
} }
$_timer_updater = @("EOT")
[Unit]
Description=Mastodon - Updater
[Timer]
OnBootSec=24min
OnUnitActiveSec=1d
Unit=mastodon_updater.service
[Install]
WantedBy=timers.target
| EOT
if ($manage_updater_task and $github_token != '') {
$_service_updater = @("EOT")
[Service]
Type=simple
User=${mastodon_user}
WorkingDirectory=${mastodon_home}/live
ExecStart=/usr/local/bin/update_mastodon.sh --debug --token "${github_token}"
[Unit]
OnFailure=status_email_antoniodelgado@%n.service
| EOT
systemd::timer { 'mastodon_updater.timer':
ensure => present,
timer_content => $_timer_updater,
service_unit => 'mastodon_updater.service',
service_content => $_service_updater,
active => true,
enable => true,
}
}
} }