From 1279e28e8399a4777c5430b1016b8a49b2c1c46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Wed, 24 Nov 2021 07:35:44 +0100 Subject: [PATCH] Disable SGE queue only if sge_execd is absent --- cluster/sge.enable.host.queue.sh | 46 +++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/cluster/sge.enable.host.queue.sh b/cluster/sge.enable.host.queue.sh index 5198bc7..25969cd 100755 --- a/cluster/sge.enable.host.queue.sh +++ b/cluster/sge.enable.host.queue.sh @@ -329,6 +329,32 @@ procs running (with the pattern: ${RED}${local_proc_pattern}${COLOR_DEBUG}) on t return "${return_proc_running}" +} +# }}} +is_proc_absent() { # {{{ + + local_proc_pattern="${1}" + + ## Proc is absent by default + return_proc_absent="0" + + local_count_proc_pattern="$(pgrep -f -- "${local_proc_pattern}" | wc -l)" + + case "${local_count_proc_pattern}" in + 0 ) ## No procs related to this pattern are running + return_proc_absent="0" + ;; + * ) ## At least one proc seems running + return_proc_absent="1" + ;; +esac + + ## Simple debug message to valid current variables + debug_message "is_proc_absent − \ +procs running (with the pattern: ${RED}${local_proc_pattern}${COLOR_DEBUG}) on the current host: ${RED}${local_count_proc_pattern}${COLOR_DEBUG}." + + return "${return_proc_absent}" + } # }}} is_file_present() { # {{{ @@ -527,22 +553,18 @@ main() { # {{{ ## If we need to watch for processes if [ "${CHECK_PROCESS}" -eq "0" ]; then - ## Ensure the SGE queue(s) are really disable without creation of any flag file - sh "${sge_disable_host_queue_script}" --force - - ## Wait few seconds - sleep "${sleep_delay}" ## If nothing related to SGE is currently running {{{ + ### First ensure that SGE queue(s) are really disable without creation of any flag file + ### Wait few seconds ### Try to start the SGE execd systemd service - ### Exit with error if the service can't start - is_proc_running "${sge_proc_pattern}" \ - || systemctl --quiet start sge_execd.service > /dev/null 2>&1 \ - || exit 4 + ### Wait few seconds + is_proc_absent "${sge_proc_pattern}" \ + && sh "${sge_disable_host_queue_script}" --force \ + && sleep "${sleep_delay}" \ + && systemctl --quiet start sge_execd.service > /dev/null 2>&1 \ + && sleep "${sleep_delay}" ## }}} - - ## Wait few seconds - sleep "${sleep_delay}" fi ## If we need to watch for upgrades