Add check cron mode

This commit is contained in:
Benjamin Renard 2024-07-14 19:47:16 +02:00
parent fcecf75613
commit a4639f158d
2 changed files with 43 additions and 31 deletions

View file

@ -39,6 +39,8 @@ Usage : check_container_upgrade [-d] [-E /path/to/engine] [container1,...]
rebuilt on status file.
--deploy-cron Start in deploy cron mode: deploy containers known as rebuilt in status
file.
--check-cron Start in check cron node: check if containers need to be updated and
trigger their rebuild.
-d Debug mode
-l Log file
-C Console logging (even if log file is specify)

View file

@ -19,6 +19,7 @@ REBUILD=0
REBUILD_DATA_DIR="/var/log/$(basename "$0")"
REBUILD_CRON=0
DEPLOY_CRON=0
CHECK_CRON=0
declare -rA CHECK_PLUGINS=(
["/usr/lib/nagios/plugins/check_apt"]="/usr/lib/nagios/plugins/check_apt -u -U -t 60 -l"
["/usr/lib/nagios/plugins/check_apk"]="/usr/lib/nagios/plugins/check_apk"
@ -161,6 +162,8 @@ Usage : $(basename "$0") [-d] [-E /path/to/engine] [container1,...]
rebuilt on status file.
--deploy-cron Start in deploy cron mode: deploy containers known as rebuilt in status
file.
--check-cron Start in check cron node: check if containers need to be updated and
trigger their rebuild.
-d Debug mode
-l Log file
-C Console logging (even if log file is specify)
@ -223,6 +226,9 @@ while [[ $idx -le $# ]]; do
--deploy-cron)
DEPLOY_CRON=1
;;
--check-cron)
CHECK_CRON=1
;;
*)
ONLY_CONTAINERS+=( "$OPT" )
;;
@ -448,6 +454,7 @@ debug "Upgradable containers (${#UPGRADABLE_CONTAINERS[@]}): $( implode ", " "${
debug "Containers with errors (${#ERRORS[@]}): $( implode ", " "${!ERRORS[@]}" )"
debug "Not found containers (${#NOTFOUNDS[@]}): $( implode ", " "${NOTFOUNDS[@]}" )"
if [[ $CHECK_CRON -eq 0 ]]; then
# Compute performance data
(( CONTAINER_COUNTS=${#CHECKED_CONTAINERS[@]}+${#NOTFOUNDS[@]} ))
PERF_DATA=(
@ -475,6 +482,7 @@ case $EXIT_CODE in
message "UNKNOWN - fail to retrieve status of ${#UNKNOWNS[@]} container(s) |$PERF_DATA_TXT"
;;
esac
fi
# Trigger container build (if need, enabled and docker compose file is provided)
if [[ $REBUILD -eq 1 ]]; then
@ -544,7 +552,7 @@ if [[ $REBUILD -eq 1 ]]; then
done
# Handle rebuilt containers
if [[ ${#REBUILT_CONTAINERS[@]} -gt 0 ]]; then
if [[ ${#REBUILT_CONTAINERS[@]} -gt 0 ]] && [[ $CHECK_CRON -eq 0 ]]; then
message
message "Some containers are ready to be recreated and restarted."
message "Run the following command to do it:"
@ -560,9 +568,11 @@ for container in "${!ERRORS[@]}"; do
message "${container}" - "${ERRORS[${container}]}"
done
if [[ $CHECK_CRON -eq 0 ]]; then
for container in "${!UP_TO_DATE[@]}"; do
message "${container}" - "${UP_TO_DATE[${container}]}"
done
fi
exit $EXIT_CODE