From 0f5e6de3120fcd291f92cef0d0de55953c426924 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Fri, 16 Feb 2024 15:24:38 +0200 Subject: [PATCH] Add systemd units to manage updater --- manifests/init.pp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index f436072..f52fcef 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -60,6 +60,12 @@ # [*nodejs_version*] # 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 ( String $ensure = 'present', String $hostname = 'mastodon.example.org', @@ -102,6 +108,8 @@ class mastodon ( }, Array $users = [], String $cert_admin_mail = 'cert-admin@example.org', + Boolean $manage_updater_task = false, + String $github_token = '', ) { case $ensure { default: { @@ -547,4 +555,38 @@ class mastodon ( active => 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, + } + } }