Disable script now manage multiple queues
This commit is contained in:
parent
8d6178fa82
commit
74b932506d
|
@ -6,7 +6,7 @@ readonly PROGDIR=$(readlink -m $(dirname "${0}"))
|
|||
readonly ARGS="${*}"
|
||||
readonly NBARGS="${#}"
|
||||
## Test if DEBUG is already defined (by parent script,…)
|
||||
[ -z "${DEBUG}" ] && readonly DEBUG=0
|
||||
[ -z "${DEBUG}" ] && readonly DEBUG=1
|
||||
|
||||
## Colors
|
||||
readonly PURPLE='\033[1;35m'
|
||||
|
@ -39,14 +39,14 @@ usage() { # {{{
|
|||
cat <<- EOF
|
||||
usage: $PROGNAME [hostname]
|
||||
|
||||
Try to disable the SGE queue of the current host (default)
|
||||
Try to disable all SGE queues of the current host (default)
|
||||
or the one passed as first argument.
|
||||
|
||||
EXAMPLES :
|
||||
- Disable SGE's queue of the current host
|
||||
- Disable SGE's queue(s) of the current host
|
||||
${PROGNAME}
|
||||
|
||||
- Disable SGE's queue of the "marvin.domain.tld" host
|
||||
- Disable SGE's queue(s) of "marvin.domain.tld" host
|
||||
${PROGNAME} marvin.domain.tld
|
||||
EOF
|
||||
|
||||
|
@ -54,24 +54,24 @@ EXAMPLES :
|
|||
# }}}
|
||||
debug_message() { # {{{
|
||||
|
||||
local_message="${1}"
|
||||
local_debug_message="${1}"
|
||||
|
||||
## Print message if DEBUG is enable (=0)
|
||||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : ${local_message}"
|
||||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : ${local_debug_message}"
|
||||
|
||||
}
|
||||
# }}}
|
||||
is_queue_enable() { # {{{
|
||||
|
||||
local_sge_hostname="${1}"
|
||||
local_sge_queue_name="${2}"
|
||||
local_queue_enable_hostname="${1}"
|
||||
local_queue_enable_name="${2}"
|
||||
## List all queues with 'disable' state and filter to the expected queue name
|
||||
## with a fake_user to avoid pending jobs for this queue
|
||||
### And count returned lines
|
||||
local_sge_queue_test=$(qstat -f -qs d -q "${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}" -u fake_user \
|
||||
local_queue_enable_test=$(qstat -f -qs d -q "${local_queue_enable_name:=/dev/null}@${local_queue_enable_hostname:=/dev/null}" -u fake_user \
|
||||
| wc -l)
|
||||
|
||||
case "${local_sge_queue_test}" in
|
||||
case "${local_queue_enable_test}" in
|
||||
0 ) ## No result so the queue is enable
|
||||
local_sge_queue_state="enable"
|
||||
return_queue_enable="0"
|
||||
|
@ -81,14 +81,14 @@ is_queue_enable() { # {{{
|
|||
return_queue_enable="1"
|
||||
;;
|
||||
* ) ## Unexpected result
|
||||
printf '%b\n' "${RED}Not able to determine the state of ${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null} queue (command return ${local_sge_queue_test} lines).${RESET}"
|
||||
printf '%b\n' "${RED}Not able to determine the state of ${local_sge_queue_name:=/dev/null}@${local_queue_enable_hostname:=/dev/null} queue (command return ${local_queue_enable_test} lines).${RESET}"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
## Simple debug message to valid current variables
|
||||
debug_message "is_queue_enable − \
|
||||
SGE queue: ${RED}${local_sge_queue_name:=/dev/null}${COLOR_DEBUG} \
|
||||
SGE queue: ${RED}${local_queue_enable_name:=/dev/null}${COLOR_DEBUG} \
|
||||
state is: ${RED}${local_sge_queue_state:=/dev/null}${COLOR_DEBUG}."
|
||||
|
||||
return "${return_queue_enable}"
|
||||
|
@ -185,22 +185,27 @@ main() { # {{{
|
|||
SGE queue(s): ${RED}${sge_queues_name_print:=/dev/null}${COLOR_DEBUG}\
|
||||
for host: ${RED}${sge_hostname:=/dev/null}${COLOR_DEBUG}."
|
||||
|
||||
## If the queue are already disable
|
||||
## If the queue(s) are already disable
|
||||
### Exit
|
||||
is_all_queue_disable "${sge_hostname}" "${sge_queues_name}" \
|
||||
&& exit 0
|
||||
|
||||
## Test all queues one by one
|
||||
for loop_queue in ${sge_queues_name}; do
|
||||
|
||||
## If the queue is enable
|
||||
### Try to disable it
|
||||
is_queue_enable "${sge_hostname}" "${sge_queue_name}" \
|
||||
&& disable_sge_queue "${sge_hostname}" "${sge_queue_name}"
|
||||
is_queue_enable "${sge_hostname}" "${loop_queue}" \
|
||||
&& disable_sge_queue "${sge_hostname}" "${loop_queue}"
|
||||
|
||||
## If the queue is still enable
|
||||
### Exit with error
|
||||
is_queue_enable "${sge_hostname}" "${sge_queue_name}" \
|
||||
&& printf '%b\n' "${RED}ERROR ${sge_queue_name}@${sge_hostname} is still enable.${RESET}" \
|
||||
is_queue_enable "${sge_hostname}" "${loop_queue}" \
|
||||
&& printf '%b\n' "${RED}ERROR ${loop_queue}@${sge_hostname} is still enable.${RESET}" \
|
||||
&& exit 4
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
# }}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue