Allow to manage max_attempts with argument (-a,-t)
With -a, --attempt, --attempts, -t or --tries.
This commit is contained in:
parent
fbe10bda8f
commit
2036f081fe
|
@ -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,6 +325,12 @@ 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
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue