2020-06-03 13:41:29 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# Vars {{{
|
|
|
|
|
readonly PROGNAME=$(basename "${0}")
|
|
|
|
|
readonly PROGDIR=$(readlink -m $(dirname "${0}"))
|
|
|
|
|
readonly ARGS="${*}"
|
|
|
|
|
readonly NBARGS="${#}"
|
2020-06-04 11:22:50 +02:00
|
|
|
|
## Test if DEBUG is already defined (by parent script,…)
|
|
|
|
|
[ -z "${DEBUG}" ] && readonly DEBUG=1
|
2020-06-03 13:41:29 +02:00
|
|
|
|
|
|
|
|
|
## Colors
|
|
|
|
|
readonly PURPLE='\033[1;35m'
|
|
|
|
|
readonly RED='\033[0;31m'
|
|
|
|
|
readonly RESET='\033[0m'
|
|
|
|
|
readonly COLOR_DEBUG="${PURPLE}"
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
manage_args() { # {{{
|
|
|
|
|
|
|
|
|
|
case "${NBARGS}" in
|
|
|
|
|
0 )
|
|
|
|
|
sge_hostname="$(hostname -f)"
|
|
|
|
|
;;
|
|
|
|
|
1 )
|
|
|
|
|
sge_hostname="${1}"
|
|
|
|
|
;;
|
|
|
|
|
* )
|
|
|
|
|
printf '%b\n' "${RED}Expect 1 or 0 argument.${RESET}"
|
|
|
|
|
printf '%b\n' "---"
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
usage() { # {{{
|
|
|
|
|
|
|
|
|
|
cat <<- EOF
|
|
|
|
|
usage: $PROGNAME [hostname]
|
|
|
|
|
|
|
|
|
|
Try to disable the SGE queue of the current host (default)
|
|
|
|
|
or the one passed as first argument.
|
|
|
|
|
|
|
|
|
|
EXAMPLES :
|
|
|
|
|
- Disable SGE's queue of the current host
|
|
|
|
|
${PROGNAME}
|
|
|
|
|
|
|
|
|
|
- Disable SGE's queue of the "marvin.domain.tld" host
|
|
|
|
|
${PROGNAME} marvin.domain.tld
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
is_queue_enable() { # {{{
|
|
|
|
|
|
|
|
|
|
local_sge_hostname="${1}"
|
|
|
|
|
local_sge_queue_name="${2}"
|
|
|
|
|
## List all available queues and filter according to both 'disable' state and the expected queue name
|
|
|
|
|
local_sge_queue_test=$(qstat -f -qs d -q "${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}" \
|
|
|
|
|
| wc -l)
|
|
|
|
|
|
|
|
|
|
case "${local_sge_queue_test}" in
|
|
|
|
|
0 ) ## No result so the queue is enable
|
|
|
|
|
local_sge_queue_state="enable"
|
|
|
|
|
return_queue_enable="0"
|
|
|
|
|
;;
|
|
|
|
|
3 ) ## Results (header + queue name) so the queue is disable
|
|
|
|
|
local_sge_queue_state="disable"
|
|
|
|
|
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.${RESET}"
|
|
|
|
|
exit 2
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
## Simple debug message to valid current variables
|
2020-06-04 11:22:20 +02:00
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : is_queue_enable − \
|
2020-06-03 13:41:29 +02:00
|
|
|
|
SGE queue: ${RED}${local_sge_queue_name:=/dev/null}${COLOR_DEBUG} \
|
|
|
|
|
state is: ${RED}${local_sge_queue_state:=/dev/null}${COLOR_DEBUG}."
|
|
|
|
|
|
|
|
|
|
return "${return_queue_enable}"
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
is_queue_disable() { # {{{
|
|
|
|
|
|
|
|
|
|
local_sge_hostname="${1}"
|
|
|
|
|
local_sge_queue_name="${2}"
|
|
|
|
|
## List all available queues and filter according to both 'disable' state and the expected queue name
|
|
|
|
|
local_sge_queue_test=$(qstat -f -qs d -q "${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}" \
|
|
|
|
|
| wc -l)
|
|
|
|
|
|
|
|
|
|
case "${local_sge_queue_test}" in
|
|
|
|
|
0 ) ## No result so the queue is enable
|
|
|
|
|
local_sge_queue_state="enable"
|
|
|
|
|
return_queue_disable="1"
|
|
|
|
|
;;
|
|
|
|
|
3 ) ## Results (header + queue name) so the queue is disable
|
|
|
|
|
local_sge_queue_state="disable"
|
|
|
|
|
return_queue_disable="0"
|
|
|
|
|
;;
|
|
|
|
|
* ) ## 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.${RESET}"
|
2020-06-03 17:51:04 +02:00
|
|
|
|
exit 3
|
2020-06-03 13:41:29 +02:00
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
## Simple debug message to valid current variables
|
2020-06-04 11:22:20 +02:00
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : is_queue_disable − \
|
2020-06-03 13:41:29 +02:00
|
|
|
|
SGE queue: ${RED}${local_sge_queue_name:=/dev/null}${COLOR_DEBUG} \
|
|
|
|
|
state is: ${RED}${local_sge_queue_state:=/dev/null}${COLOR_DEBUG}."
|
|
|
|
|
|
|
|
|
|
return "${return_queue_disable}"
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
disable_sge_queue() { # {{{
|
|
|
|
|
|
|
|
|
|
local_sge_hostname="${1}"
|
|
|
|
|
local_sge_queue_name="${2}"
|
|
|
|
|
|
|
|
|
|
## Simple debug message to valid current variables
|
2020-06-04 11:22:20 +02:00
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : disable_sge_queue − \
|
2020-06-03 13:41:29 +02:00
|
|
|
|
Try to disable SGE queue: ${RED}${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}${COLOR_DEBUG}."
|
|
|
|
|
|
|
|
|
|
## SGE command to disable the queue
|
|
|
|
|
qmod --disable "${local_sge_queue_name}@${local_sge_hostname}" \
|
|
|
|
|
&& return_disable_queue="${?}"
|
|
|
|
|
|
|
|
|
|
return "${return_disable_queue}"
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
main() { # {{{
|
|
|
|
|
|
|
|
|
|
manage_args "${ARGS}"
|
|
|
|
|
|
|
|
|
|
sge_queue_name="$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
|
|
|
|
|
| grep "queue name" \
|
|
|
|
|
| cut -d"'" -f2 )"
|
|
|
|
|
|
|
|
|
|
## Simple debug message with color to valid current variables
|
2020-06-04 11:22:20 +02:00
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : main − Try to manage \
|
2020-06-03 13:41:29 +02:00
|
|
|
|
SGE queue: ${RED}${sge_queue_name:=/dev/null}${COLOR_DEBUG} \
|
|
|
|
|
for host: ${RED}${sge_hostname:=/dev/null}${COLOR_DEBUG}."
|
|
|
|
|
|
2020-06-03 17:51:04 +02:00
|
|
|
|
## If the queue is already disable
|
|
|
|
|
### Exit
|
|
|
|
|
is_queue_disable "${sge_hostname}" "${sge_queue_name}" \
|
|
|
|
|
&& exit 0
|
|
|
|
|
|
2020-06-03 13:41:29 +02:00
|
|
|
|
## 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}"
|
|
|
|
|
|
2020-06-03 17:51:31 +02:00
|
|
|
|
## 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}" \
|
|
|
|
|
&& exit 4
|
|
|
|
|
|
2020-06-03 13:41:29 +02:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
main
|
|
|
|
|
|
|
|
|
|
exit 0
|