From 06d7fabf4b9460f6d7d3b053831cac2d52c216b1 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Wed, 26 Feb 2025 12:30:30 +0100 Subject: [PATCH] Run cronjob in scriptherder and report errors found --- manifests/app_type.pp | 13 +++++++++---- manifests/multinode.pp | 13 +++++++++---- templates/application/scan_external_mounts.sh | 13 ++++++++++++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/manifests/app_type.pp b/manifests/app_type.pp index 35b628b..851bd45 100644 --- a/manifests/app_type.pp +++ b/manifests/app_type.pp @@ -110,11 +110,16 @@ define sunetdrive::app_type ( content => template('sunetdrive/application/scan_external_mounts.sh'), mode => '0744', } + sunet::scriptherder::cronjob { 'scriptherder_scan_external_mounts': + cmd => '/usr/local/bin/scan_external_mounts', + hour => '1', + minute => '20', + ok_criteria => ['exit_status=0','max_age=2d'], + warn_criteria => ['exit_status=1','max_age=3d'], + } cron { 'scan_external_mounts': - command => '/usr/local/bin/scan_external_mounts', - user => 'root', - minute => '20', - hour => '1', + ensure => absent, + command => 'true', } } file { '/opt/nextcloud/cron.sh': diff --git a/manifests/multinode.pp b/manifests/multinode.pp index 50594ee..9ebec47 100644 --- a/manifests/multinode.pp +++ b/manifests/multinode.pp @@ -55,11 +55,16 @@ class sunetdrive::multinode ( content => template('sunetdrive/application/scan_external_mounts.sh'), mode => '0744', } + sunet::scriptherder::cronjob { 'scriptherder_scan_external_mounts': + cmd => '/usr/local/bin/scan_external_mounts', + hour => '1', + minute => '20', + ok_criteria => ['exit_status=0','max_age=2d'], + warn_criteria => ['exit_status=1','max_age=3d'], + } cron { 'scan_external_mounts': - command => '/usr/local/bin/scan_external_mounts', - user => 'root', - minute => '20', - hour => '1', + ensure => absent, + command => 'true', } } file { '/usr/local/bin/nocc': diff --git a/templates/application/scan_external_mounts.sh b/templates/application/scan_external_mounts.sh index d1874b1..ef58cd8 100644 --- a/templates/application/scan_external_mounts.sh +++ b/templates/application/scan_external_mounts.sh @@ -1,5 +1,6 @@ #!/bin/bash +error_ids="" # Only run if this is the only instance of this script running # note: since this script forks to run pgrep, we need -eq 2 here if [[ $(pgrep -f "${0}" | wc -l) -eq 2 ]]; then @@ -8,7 +9,17 @@ if [[ $(pgrep -f "${0}" | wc -l) -eq 2 ]]; then sleep $((16#$(ip a | grep "link/ether" | head -1 | awk -F ':' '{print $6}' | awk '{print $1}') / 2))m for container in $(get_containers); do for id in $(nocc "${container}" files_external:list --all --output json | jq '.[].mount_id' | jq .); do - nocc "${container}" files_external:scan "${id}" + nocc "${container}" files_external:scan "${id}" | grep Error + # shellcheck disable=SC2181 + if [[ ${?} -eq 0 ]]; then + error_ids="${error_ids} ${id}" + fi done done fi + +if [[ -n "${error_ids}" ]]; then + echo "Errors found in the following mounts: ${error_ids}" + exit 1 +fi +exit 0