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() { # {{{
|
usage() { # {{{
|
||||||
|
|
||||||
cat <<- EOF
|
cat <<- EOF
|
||||||
usage: $PROGNAME
|
usage: $PROGNAME [-a|-d|-h|-t]
|
||||||
|
|
||||||
Verify if any APT package upgrade is available and
|
Verify if any APT package upgrade is available and
|
||||||
try to prepare the host by :
|
try to prepare the host by :
|
||||||
|
@ -39,7 +39,15 @@ EXAMPLES :
|
||||||
- Verify upgrade and prepare the current host
|
- Verify upgrade and prepare the current host
|
||||||
${PROGNAME}
|
${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 :
|
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
|
-d,--debug
|
||||||
Enable debug messages.
|
Enable debug messages.
|
||||||
|
|
||||||
|
@ -61,12 +69,18 @@ debug_message() { # {{{
|
||||||
# }}}
|
# }}}
|
||||||
define_vars() { # {{{
|
define_vars() { # {{{
|
||||||
|
|
||||||
## If sge_hostname wasn't defined
|
## If sge_hostname wasn't defined (environment variable,…)
|
||||||
if [ -z "${sge_hostname}" ]; then
|
if [ -z "${sge_hostname}" ]; then
|
||||||
## Use local host for sge_hostname
|
## Use local host for sge_hostname
|
||||||
sge_hostname="$(hostname -f)"
|
sge_hostname="$(hostname -f)"
|
||||||
fi
|
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)
|
## Script used to disable SGE queue(s)
|
||||||
sge_disable_host_queue_script="${PROGDIR}/sge.disable.host.queue.sh"
|
sge_disable_host_queue_script="${PROGDIR}/sge.disable.host.queue.sh"
|
||||||
|
|
||||||
|
@ -248,11 +262,11 @@ main() { # {{{
|
||||||
&& exit 0
|
&& exit 0
|
||||||
## }}}
|
## }}}
|
||||||
|
|
||||||
## If pending upgrade since 3 attempts {{{
|
## If pending upgrade since max_attempts (default: 3) {{{
|
||||||
## APT package upgrade is available
|
## APT package upgrade is available
|
||||||
### Create a temp file
|
### Create a temp file
|
||||||
### Disable SGE queue
|
### 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}" \
|
&& touch "${APT_TMP_FILE}" && echo "APT upgrade is available." >> "${APT_TMP_FILE}" \
|
||||||
&& sh "${sge_disable_host_queue_script}" \
|
&& sh "${sge_disable_host_queue_script}" \
|
||||||
&& exit 0
|
&& exit 0
|
||||||
|
@ -278,7 +292,7 @@ main() { # {{{
|
||||||
&& exit 0
|
&& 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}" \
|
touch "${APT_TMP_FILE}" && echo "APT upgrade is available." >> "${APT_TMP_FILE}" \
|
||||||
&& debug_message "main − Add content to temp file for pending upgrade(s)." \
|
&& debug_message "main − Add content to temp file for pending upgrade(s)." \
|
||||||
&& exit 0
|
&& exit 0
|
||||||
|
@ -290,7 +304,7 @@ main() { # {{{
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Manage arguments # {{{
|
# 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
|
if [ ! "${NBARGS}" -eq "0" ]; then
|
||||||
|
|
||||||
|
@ -311,15 +325,21 @@ if [ ! "${NBARGS}" -eq "0" ]; then
|
||||||
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
|
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
|
||||||
|
|
||||||
case "${1}" in
|
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
|
DEBUG=0
|
||||||
;;
|
;;
|
||||||
-h|--help ) ## help
|
-h|--help ) ## help
|
||||||
usage
|
usage
|
||||||
## Exit after help informations
|
## Exit after help informations
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
* ) ## unknow option
|
* ) ## unknow option
|
||||||
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
|
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
|
||||||
printf '%b\n' "---"
|
printf '%b\n' "---"
|
||||||
usage
|
usage
|
||||||
|
|
Loading…
Reference in New Issue