From 7f8947dac9b659acd486095f16522f147f1b7bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Fri, 25 Sep 2020 13:24:20 +0200 Subject: [PATCH] Disable queue if pending upgrade for more than 3 days --- cluster/apt.check.update.sh | 45 +++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/cluster/apt.check.update.sh b/cluster/apt.check.update.sh index 5150fbd..265dbc0 100755 --- a/cluster/apt.check.update.sh +++ b/cluster/apt.check.update.sh @@ -139,17 +139,43 @@ is_sge_slots_more_than_percentage() { # {{{ ## Used slots is greater or equal than expected percentage return_sge_slots_percentage="0" ## Simple debug message to valid current variable - debug_message "is_sge_slots_more_than_percentage (${local_percentage}%) − \ -Used slots has reached ${local_percentage}% of total slots: ${RED}${local_sge_slots_used:=/dev/null}${COLOR_DEBUG}/${local_sge_slots}." + debug_message "is_sge_slots_more_than_percentage − \ +Used slots has reached ${RED}${local_percentage}%${COLOR_DEBUG} of total slots: ${RED}${local_sge_slots_used:=/dev/null}${COLOR_DEBUG}/${local_sge_slots}." else return_sge_slots_percentage="1" ## Simple debug message to valid current variable - debug_message "is_sge_slots_more_than_percentage (${local_percentage}%) − \ -Used slots did not reach ${local_percentage}% of total slots: ${RED}${local_sge_slots_used:=/dev/null}${COLOR_DEBUG}/${local_sge_slots}." + debug_message "is_sge_slots_more_than_percentage − \ +Used slots did not reach ${RED}${local_percentage}%${COLOR_DEBUG} of total slots: ${RED}${local_sge_slots_used:=/dev/null}${COLOR_DEBUG}/${local_sge_slots}." fi return "${return_sge_slots_percentage}" +} +# }}} +is_pending_upgrade_more_than_days() { # {{{ + + local_days="${1}" + + local_line_size="24" + + local_max_file_size="$(( ${local_days} * ${local_line_size} ))" + + debug_message "is_pending_upgrade_more_than_days (${local_days}) − \ +Check if ${APT_TMP_FILE} has a size bigger than ${RED}${local_max_file_size:=/dev/null}${COLOR_DEBUG} bytes (${local_days} days * ${local_line_size} bytes size for one line)." + + if [ $(find "${APT_TMP_FILE}" -type f -size +"${local_max_file_size}"c 2>/dev/null) ]; then + ## Temp file seems to exist for more than the maximum days + return_pending_upgrade_more_than_days="0" + debug_message "is_pending_upgrade_more_than_days − \ +There is pending upgrade(s) for more than ${RED}${local_days:=/dev/null}${COLOR_DEBUG} days." + else + return_pending_upgrade_more_than_days="1" + debug_message "is_pending_upgrade_more_than_days − \ +NO pending upgrades for more than ${RED}${local_days:=/dev/null}${COLOR_DEBUG} days." + fi + + return "${return_pending_upgrade_more_than_days}" + } # }}} is_sge_slots_empty() { # {{{ @@ -224,6 +250,17 @@ main() { # {{{ && exit 0 ## }}} + ## If pending upgrade since 3~4 days AND {{{ + ## APT package upgrade is available + ### Create a temp file + ### Disable SGE queue + is_pending_upgrade_more_than_days "3" \ + && is_apt_upgrade_present \ + && touch "${APT_TMP_FILE}" && echo "APT upgrade is available." >> "${APT_TMP_FILE}" \ + && sh "${sge_disable_host_queue_script}" \ + && exit 0 + ## }}} + ## If SGE used slots is NULL AND {{{ ## APT package upgrade is available ### Create a temp file