diff --git a/cluster/sge.enable.host.queue.sh b/cluster/sge.enable.host.queue.sh index 2816ed5..b31ea85 100755 --- a/cluster/sge.enable.host.queue.sh +++ b/cluster/sge.enable.host.queue.sh @@ -11,6 +11,9 @@ readonly NBARGS="${#}" # If output message should be displayed [ -z "${OUTPUT_MESSAGE}" ] && OUTPUT_MESSAGE=0 +# If SGE queues should be re-enable even if disabled manually (by a user) +[ -z "${FORCE_MODE}" ] && FORCE_MODE=1 + # Maco temp file readonly MACO_TMP_FILE="/tmp/.maco.upgrade" readonly MACO_TMP_URGENT_FILE="/tmp/.maco.urgent.upgrade" @@ -31,7 +34,7 @@ readonly COLOR_DEBUG="${PURPLE}" usage() { # {{{ cat <<- EOF -usage: $PROGNAME [--help] [-d|-h|-q] [hostname] +usage: $PROGNAME [--help] [-d|-f|-h|-q] [hostname] Try to enable all SGE queues of the current host (default), if no pending upgrades (Maco, APT) are present, @@ -49,6 +52,10 @@ OPTIONS : -d,--debug Enable debug messages. + -f,--force + Force to (re)enable a queue even if it was + previously manually disabled (by a user). + --help Print this help message. @@ -58,7 +65,7 @@ OPTIONS : -q,--quiet Disable messages on standard output (except for error). - EOF +EOF } # }}} @@ -181,6 +188,9 @@ is_queue_disable() { # {{{ 0 ) ## No result so the queue is enable local_sge_queue_state="enable" return_queue_disable="1" + + ## Ensure to remove any previously setted file + rm -f -- "${sge_queue_deactivator}" ;; 3 ) ## Results (header + queue name) so the queue is disable local_sge_queue_state="disable" @@ -228,17 +238,15 @@ enable_sge_queue() { # {{{ local_sge_hostname="${1}" local_sge_queue_name="${2}" - local_sge_disable="/etc/.sge.${local_sge_queue_name}.disable" - - ## If the queue was previously disabled by another script - if [ -f "${local_sge_disable}" ]; then + ## If the queue was previously disabled by another script OR if FORCE_MODE is enable + if [ -f "${sge_queue_deactivator}" ] || [ "${FORCE_MODE}" -eq "0" ]; then debug_message "enable_sge_queue − \ -Try to enable SGE queue: ${RED}${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}${COLOR_DEBUG}." +Previously disabled by a script (or FORCE is enable), try to enable SGE queue: ${RED}${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}${COLOR_DEBUG}." ## SGE command to enable the queue qmod --enable "${local_sge_queue_name}@${local_sge_hostname}" \ && return_enable_queue="${?}" else - message "SGE queue: ${RED}${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}${RESET} was manually disabled, please re-enable it ${RED}manually${RESET}." + message "SGE queue: ${RED}${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}${RESET} was manually disabled, please re-enable it ${RED}manually${RESET} (or use --force option)." return_enable_queue="1" fi @@ -281,16 +289,23 @@ for host: ${RED}${sge_hostname:=/dev/null}${COLOR_DEBUG}." ## Test all queues one by one for loop_queue in ${sge_queues_name}; do + ## File previously set if the queue was disabled by a script + ## "automatically disabled" for an upgrade + sge_queue_deactivator="/etc/.sge.${local_sge_queue_name}.disable" + ## If the queue is disable ### Try to enable it is_queue_disable "${sge_hostname}" "${loop_queue}" \ && enable_sge_queue "${sge_hostname}" "${loop_queue}" - ## If the queue is still disable - ### Exit with error - is_queue_disable "${sge_hostname}" "${loop_queue}" \ - && printf '%b\n' "${RED}ERROR ${loop_queue}@${sge_hostname} is still disable.${RESET}" \ - && exit 4 + ## Don't consider manually disabled queue as an error except if FORCE_MODE was specified + if [ -f "${sge_queue_deactivator}" ] || [ "${FORCE_MODE}" -eq "0" ]; then + ## If the queue is still disable + ### Exit with error + is_queue_disable "${sge_hostname}" "${loop_queue}" \ + && printf '%b\n' "${RED}ERROR ${loop_queue}@${sge_hostname} is still disable.${RESET}" \ + && exit 4 + fi done @@ -328,6 +343,9 @@ if [ ! "${NBARGS}" -eq "0" ]; then -d|--debug ) ## debug DEBUG=0 ;; + -f|--force ) ## Force to enable SGE queue + FORCE_MODE=0 + ;; --help ) ## help usage ## Exit after help informations