diff --git a/cluster/apt.check.update.sh b/cluster/apt.check.update.sh index bb80ccb..ccf0ea5 100755 --- a/cluster/apt.check.update.sh +++ b/cluster/apt.check.update.sh @@ -29,7 +29,7 @@ readonly COLOR_DEBUG="${PURPLE}" usage() { # {{{ cat <<- EOF -usage: $PROGNAME +usage: $PROGNAME [-a|-d|-h|-t] Verify if any APT package upgrade is available and try to prepare the host by : @@ -39,7 +39,15 @@ 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. @@ -61,12 +69,18 @@ debug_message() { # {{{ # }}} define_vars() { # {{{ - ## If sge_hostname wasn't defined + ## If sge_hostname wasn't defined (environment variable,…) if [ -z "${sge_hostname}" ]; then ## Use local host for sge_hostname 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" @@ -248,11 +262,11 @@ main() { # {{{ && exit 0 ## }}} - ## If pending upgrade since 3 attempts {{{ + ## 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 "3" \ + 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 @@ -278,7 +292,7 @@ main() { # {{{ && exit 0 ## }}} - ## After all just add content to a temp file {{{ + ## 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)." \ && exit 0 @@ -290,7 +304,7 @@ main() { # {{{ # }}} # Manage arguments # {{{ -# This code can't be in a function due to arguments +# This code can't be in a function due to argument management if [ ! "${NBARGS}" -eq "0" ]; then @@ -311,15 +325,21 @@ if [ ! "${NBARGS}" -eq "0" ]; then while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do case "${1}" in - -d|--debug ) ## debug + -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 ;; - -h|--help ) ## help + -h|--help ) ## help usage ## Exit after help informations exit 0 ;; - * ) ## unknow option + * ) ## unknow option printf '%b\n' "${RED}Invalid option: ${1}${RESET}" printf '%b\n' "---" usage