Remove too complicated tests (attempts, % used slots)

This commit is contained in:
Jeremy Gardais 2020-12-03 12:38:50 +01:00
parent fc37812f7b
commit 06f7dadcd8
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 1 additions and 131 deletions

View File

@ -29,7 +29,7 @@ readonly COLOR_DEBUG="${PURPLE}"
usage() { # {{{
cat <<- EOF
usage: $PROGNAME [-a|-d|-h|-t]
usage: $PROGNAME [-d|-h|-t]
Verify if any APT package upgrade is available and
try to prepare the host by:
@ -39,15 +39,7 @@ EXAMPLES:
- Verify upgrade and prepare the current host
${PROGNAME}
- Prepare the current host (if pending upgrade) only after 6 runs
if sge_slots_used is under 75% of total SGE slots.
${PROGNAME} --attempts 6
OPTIONS:
-a,--attempt,--attempts,-t,--tries INT_MAX_ATTEMPTS
Number of time this script must be run to disable the host
if sge_slots_used is under 75% of total SGE slots.
-d,--debug
Enable debug messages.
@ -75,20 +67,9 @@ define_vars() { # {{{
sge_hostname="$(hostname -f)"
fi
## If max_attempts wasn't defined
if [ -z "${max_attempts}" ]; then
## Allow maximum 3 attempts before disable a host
max_attempts="3"
fi
## Script used to disable SGE queue(s)
sge_disable_host_queue_script="${PROGDIR}/sge.disable.host.queue.sh"
## Get the number of total SGE slots
sge_slots=$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
| grep --max-count=1 -- "'slots'" \
| sed 's;.*<queuevalue.*>\(.*\)</queuevalue>;\1;')
## Get the number of SGE used slots
sge_slots_used=$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
| grep --max-count=1 -- "'slots_used'" \
@ -142,57 +123,6 @@ APT upgrade available for this system: ${RED}${local_apt_upgrade_number:=/dev/nu
return "${return_apt_upgrade_present}"
}
# }}}
is_sge_slots_more_than_percentage() { # {{{
local_percentage="${1}"
## Get the expected percentage of total SGE slots
local_sge_slots_percentage=$(echo "${sge_slots}" \
| awk -v percentage="0.${local_percentage}" '{ print int($1 * percentage) }')
if [ "${sge_slots_used}" -ge "${local_sge_slots_percentage}" ]; then
## 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 \
Used slots has reached ${RED}${local_percentage}%${COLOR_DEBUG} of total slots: ${RED}${sge_slots_used:=/dev/null}${COLOR_DEBUG}/${sge_slots}."
else
return_sge_slots_percentage="1"
## Simple debug message to valid current variable
debug_message "is_sge_slots_more_than_percentage \
Used slots did not reach ${RED}${local_percentage}%${COLOR_DEBUG} of total slots: ${RED}${sge_slots_used:=/dev/null}${COLOR_DEBUG}/${sge_slots}."
fi
return "${return_sge_slots_percentage}"
}
# }}}
is_pending_upgrade_more_than_attempts() { # {{{
local_attempts="${1}"
local_line_size="26"
local_max_file_size="$(( ${local_attempts} * ${local_line_size} ))"
debug_message "is_pending_upgrade_more_than_attempts (${local_attempts}) \
Check if ${APT_TMP_FILE} has a size bigger than ${RED}${local_max_file_size:=/dev/null}${COLOR_DEBUG} bytes (${local_attempts} attempts * ${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 attempts
return_pending_upgrade_more_than_attempts="0"
debug_message "is_pending_upgrade_more_than_attempts \
There is pending upgrade(s) for more than ${RED}${local_attempts:=/dev/null}${COLOR_DEBUG} attempts."
else
return_pending_upgrade_more_than_attempts="1"
debug_message "is_pending_upgrade_more_than_attempts \
NO pending upgrades for more than ${RED}${local_attempts:=/dev/null}${COLOR_DEBUG} attempts."
fi
return "${return_pending_upgrade_more_than_attempts}"
}
# }}}
is_sge_slots_empty() { # {{{
@ -210,30 +140,6 @@ SGE slots currently in use: ${RED}${sge_slots_used:=/dev/null}${COLOR_DEBUG}."
return "${return_sge_slots_empty}"
}
# }}}
is_pending_job_empty() { # {{{
## Count the number of pending jobs (qw state only)
## Excluding root's jobs
local_pending_jobs="$(qstat -s p -u '*' \
| grep --count --perl-regexp -- "(?=.*?\bqw\b)((?!root).)*$")"
case "${local_pending_jobs}" in
0 ) ## Pending jobs list is empty
return_pending_job_empty="0"
;;
* ) ## Some jobs are waiting
return_pending_job_empty="1"
;;
esac
## Simple debug message to valid current variable
debug_message "is_pending_job_empty \
Pending jobs for the compute cluster: ${RED}${local_pending_jobs:=/dev/null}${COLOR_DEBUG}."
return "${return_pending_job_empty}"
}
# }}}
main() { # {{{
@ -252,26 +158,6 @@ main() { # {{{
## If APT package upgrade(s) is available AND
is_apt_upgrade_present \
&& {
## If SGE used slots is more than 75% of total slots {{{
## APT package upgrade is available
### Create a temp file
### Disable SGE queue
is_sge_slots_more_than_percentage "75" \
&& touch "${APT_TMP_FILE}" && echo "APT upgrade is available." >> "${APT_TMP_FILE}" \
&& sh "${sge_disable_host_queue_script}" \
&& exit 0
## }}}
## If pending upgrade since max_attempts (default: 3) {{{
## APT package upgrade is available
### Create a temp file
### Disable SGE queue
is_pending_upgrade_more_than_attempts "${max_attempts}" \
&& 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 {{{
## APT package upgrade is available
### Create a temp file
@ -282,16 +168,6 @@ main() { # {{{
&& exit 0
## }}}
## If pending job list is empty {{{
## APT package upgrade is available
### Create a temp file
### Disable SGE queue
is_pending_job_empty \
&& touch "${APT_TMP_FILE}" && echo "APT upgrade is available." >> "${APT_TMP_FILE}" \
&& sh "${sge_disable_host_queue_script}" \
&& exit 0
## }}}
## After all just add content to a temp file (+1 attempt) {{{
touch "${APT_TMP_FILE}" && echo "APT upgrade is available." >> "${APT_TMP_FILE}" \
&& debug_message "main Add content to temp file for pending upgrade(s)." \
@ -325,12 +201,6 @@ if [ ! "${NBARGS}" -eq "0" ]; then
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
case "${1}" in
-a|--attempt|--attempts|-t|--tries ) ## Fix the maximum attempts
## Move to the next argument
shift
## Define max_attempts with this argument
max_attempts="${1}"
;;
-d|--debug ) ## debug
DEBUG=0
;;