Run cronjob in scriptherder and report errors found

This commit is contained in:
Micke Nordin 2025-02-26 12:30:30 +01:00
parent 800b2c4afc
commit 06d7fabf4b
Signed by untrusted user: Micke
GPG key ID: 0DA0A7A5708FE257
3 changed files with 30 additions and 9 deletions

View file

@ -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':

View file

@ -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':

View file

@ -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