2020-06-22 11:33:31 +02:00
#!/bin/sh
# Vars {{{
readonly PROGNAME = $( basename " ${ 0 } " )
readonly PROGDIR = $( readlink -m $( dirname " ${ 0 } " ) )
readonly ARGS = " ${ * } "
readonly NBARGS = " ${# } "
## Test if DEBUG is already defined (by parent script,…)
2020-06-22 13:48:26 +02:00
[ -z " ${ DEBUG } " ] && DEBUG = 1
2020-06-22 11:33:31 +02:00
2020-06-22 14:04:57 +02:00
# If output message should be displayed
[ -z " ${ OUTPUT_MESSAGE } " ] && OUTPUT_MESSAGE = 0
2021-01-06 11:52:24 +01:00
# APT temp file to monitor
readonly APT_TMP_FILE = "/tmp/.apt.upgrade"
2020-06-22 12:22:01 +02:00
# Maco temp file
2021-01-06 12:07:31 +01:00
readonly MACO_LOCAL_DIR = "/opt/maco"
readonly MACO_TMP_FILE = " ${ MACO_LOCAL_DIR } /.maco.upgrade "
readonly MACO_TMP_URGENT_FILE = " ${ MACO_LOCAL_DIR } /.maco.urgent.upgrade "
2020-06-22 12:22:01 +02:00
2021-01-06 11:52:24 +01:00
# Maco status file
readonly MACO_STATUS_FILE = "/var/fr.univ-rennes1.ipr.maco.machinestate.txt"
2020-06-22 12:22:01 +02:00
2021-11-18 12:11:04 +01:00
# Default sleep delay
readonly SLEEP_DELAY_DEFAULT = "15"
2020-06-22 11:33:31 +02:00
## Colors
readonly PURPLE = '\033[1;35m'
readonly RED = '\033[0;31m'
readonly RESET = '\033[0m'
readonly COLOR_DEBUG = " ${ PURPLE } "
# }}}
usage( ) { # {{{
cat <<- EOF
2021-11-18 12:11:04 +01:00
usage: $PROGNAME [ --help] [ -d| -f| -h| -q| -s] [ hostname]
2020-06-22 11:33:31 +02:00
2020-06-22 14:04:57 +02:00
Try to enable all SGE queues of the current host ( default) ,
if no pending upgrades ( Maco, APT) are present,
or to the one passed as first argument ( no upgrades checking) .
2020-06-22 11:33:31 +02:00
EXAMPLES :
- Enable SGE' s queue( s) of the current host
${ PROGNAME }
- Enable SGE' s queue( s) of "marvin.domain.tld" host
${ PROGNAME } marvin.domain.tld
2020-06-22 14:20:45 +02:00
${ PROGNAME } -h marvin.domain.tld
2020-06-22 14:04:57 +02:00
2021-11-18 12:11:04 +01:00
- Wait 30 seconds after the start of sge_execd ( default: ${ SLEEP_DELAY_DEFAULT } )
${ PROGNAME } -s 30
2020-06-22 14:04:57 +02:00
OPTIONS :
2020-06-22 14:20:45 +02:00
-d,--debug
Enable debug messages.
2020-06-22 17:12:14 +02:00
-f,--force
2020-07-06 17:05:06 +02:00
Try to ( re) enable a queue even if it was previously
manually disabled ( by a user) and avoid all checks
( pending upgrades, running processes, files,…) .
2020-06-22 17:12:14 +02:00
2020-06-22 14:04:57 +02:00
--help
Print this help message.
2020-06-22 14:20:45 +02:00
-h,--host,--hostname SGE_HOST_TO_MANAGE
Manage SGE' s queue( s) of "SGE_HOST_TO_MANAGE" host.
2020-06-22 14:04:57 +02:00
-q,--quiet
Disable messages on standard output ( except for error) .
2021-11-18 12:11:04 +01:00
-s,--sleep
Set a different delay to wait after the sge_execd start
( default: ${ SLEEP_DELAY_DEFAULT } ) .
2020-06-22 17:12:14 +02:00
EOF
2020-06-22 11:33:31 +02:00
}
# }}}
debug_message( ) { # {{{
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_debug_message } "
2020-08-20 10:02:11 +02:00
return 0
2020-06-22 14:04:57 +02:00
}
# }}}
message( ) { # {{{
local_message = " ${ 1 } "
## Print message if OUTPUT_MESSAGE is enable (=0)
[ " ${ OUTPUT_MESSAGE } " -eq "0" ] && printf '%b\n' " ${ local_message } "
return 0
2020-06-22 20:02:52 +02:00
}
# }}}
define_vars( ) { # {{{
2021-11-18 12:11:04 +01:00
## If sge_hostname wasn't defined {{{
2020-06-22 20:02:52 +02:00
if [ -z " ${ sge_hostname } " ] ; then
## Use local host for sge_hostname
sge_hostname = " $( hostname -f) "
fi
2021-11-18 12:11:04 +01:00
## }}}
## If sleep_delay wasn't defined (argument) {{{
if [ -z " ${ sleep_delay } " ] ; then
## Use default value
readonly sleep_delay = " ${ SLEEP_DELAY_DEFAULT } "
fi
## }}}
2020-06-22 20:02:52 +02:00
2021-11-23 17:14:48 +01:00
## If the host to manage is the current one {{{
2020-06-22 20:27:10 +02:00
if is_current_host " ${ sge_hostname } " ; then
debug_message " define_vars − \
${ sge_hostname } is the current host."
## Enable to verify if pending upgrades are present
CHECK_UPGRADE = "0"
2020-07-06 15:07:23 +02:00
## Enable to watch if some files are present
CHECK_FILE = "0"
2020-07-06 17:05:06 +02:00
## Enable to verify if upgrades are running
CHECK_PROCESS = "0"
2020-06-22 20:42:09 +02:00
else ## In case of a remote host
2020-06-22 20:27:10 +02:00
debug_message " define_vars − \
${ sge_hostname } is not the current host."
2020-06-22 20:42:09 +02:00
## Force to (re)enable SGE queue(s) in any case
FORCE_MODE = "0"
fi
2021-11-23 17:14:48 +01:00
## }}}
2020-06-22 20:42:09 +02:00
2021-11-23 17:14:48 +01:00
## If FORCE_MODE was defined and enabled {{{
2020-06-22 20:42:09 +02:00
if [ -n " ${ FORCE_MODE } " ] && [ " ${ FORCE_MODE } " -eq "0" ] ; then
## Disable upgrade checking (remote host, asked behaviour,…)
2020-06-22 20:27:10 +02:00
CHECK_UPGRADE = "1"
2020-07-06 15:07:23 +02:00
## Disable files monitoring
CHECK_FILE = "1"
2020-07-06 17:05:06 +02:00
## Disable process checking (remote host, asked behaviour,…)
CHECK_PROCESS = "1"
2020-06-22 20:42:09 +02:00
else
## Ensure to define a value
2020-06-22 20:27:10 +02:00
FORCE_MODE = "1"
fi
2021-11-23 17:14:48 +01:00
## }}}
2020-06-22 20:27:10 +02:00
2021-11-23 17:14:48 +01:00
## Get all queues name {{{
2020-06-22 20:02:52 +02:00
sge_queues_name = " $( qhost -h " ${ sge_hostname : =/dev/null } " -q -xml \
| grep "queue name" \
| cut -d"'" -f2 ) "
sge_queues_name_print = " $( qhost -h " ${ sge_hostname : =/dev/null } " -q -xml \
| grep "queue name" \
| cut -d"'" -f2 \
| tr -s '\n' ' ' ) "
2021-11-23 17:14:48 +01:00
## }}}
2020-06-22 20:02:52 +02:00
2021-11-23 17:14:48 +01:00
## List of process pattern to monitor {{{
2020-07-06 11:30:24 +02:00
maco_proc_pattern = "(/opt/maco/bin/maco.autoupdate.sh)"
apt_proc_pattern = "(aptitude.*full-upgrade|/usr/bin/dpkg.*--configure|dpkg-deb|/bin/sh /usr/lib/needrestart/dpkg-status)"
2020-07-06 17:19:07 +02:00
sge_proc_pattern = "(/usr/lib/gridengine/sge_execd)"
2021-11-23 17:14:48 +01:00
## }}}
## List of files to monitor {{{
2020-07-06 15:07:23 +02:00
file_nologin_path = "/etc/nologin"
2020-07-06 16:16:25 +02:00
cluster_dir = "/opt/ipr/cluster"
sge_queue_flag_pattern = " ${ cluster_dir } /.sge.*.disable "
2021-11-23 17:14:48 +01:00
## }}}
## Script used to disable SGE queue(s)
sge_disable_host_queue_script = " ${ PROGDIR } /sge.disable.host.queue.sh "
2020-06-22 20:27:10 +02:00
}
# }}}
2021-01-26 18:23:01 +01:00
is_sge_host( ) { # {{{
2021-11-16 10:18:59 +01:00
## Check if SGE commands (qconf) are available
if [ " $( command -v qconf) " ] ; then
2021-01-26 18:23:01 +01:00
debug_message " is_sge_host − \
SGE seems present on this host."
2021-11-16 10:18:59 +01:00
### And verify if the host is fully configured as a submit host
if qconf -ss | grep --word-regexp --quiet $( hostname -f) ; then
debug_message " is_sge_host − \
The host seems configured as a SGE submit host."
return_is_sge_host = "0"
else
return_is_sge_host = "1"
debug_message " is_sge_host − \
This host is not yet configured as a SGE submit host."
fi
2021-01-26 18:23:01 +01:00
else
return_is_sge_host = "1"
debug_message " is_sge_host − \
SGE is not present on this host."
fi
return " ${ return_is_sge_host } "
2021-03-11 14:50:25 +01:00
}
# }}}
is_sge_master_available( ) { # {{{
## Check with Netcat if SGE master (sge_qmaster) is reachable from this host.
### -z: Only scan for listening daemons, without sending any data to them.
### -w 10: Timeout the test after 10 seconds.
if nc -z -w 10 " ${ sge_master_uri } " " ${ sge_master_port } " ; then
return_is_sge_master_available = "0"
debug_message " is_sge_master_available − \
SGE Master ( ${ sge_master_uri } :${ sge_master_port } ) is reachable from this host."
else
return_is_sge_master_available = "1"
debug_message " is_sge_master_available − \
SGE Master ( ${ sge_master_uri } :${ sge_master_port } ) is not reachable from this host."
fi
return " ${ return_is_sge_master_available } "
2021-01-26 18:23:01 +01:00
}
# }}}
2020-06-22 20:27:10 +02:00
is_current_host( ) { # {{{
local_current_host = " ${ 1 } "
local_current_fqdn = $( hostname -f)
## Test if the sge_host to manage is the current host
if [ " ${ local_current_host } " = " ${ local_current_fqdn } " ] ; then
local_current_host_return = "0"
else
local_current_host_return = "1"
fi
return " ${ local_current_host_return } "
2020-06-22 11:33:31 +02:00
}
# }}}
2020-06-22 12:22:01 +02:00
is_apt_upgrade_present( ) { # {{{
## No pending upgrade by default
return_apt_upgrade_present = "1"
2020-06-22 20:46:37 +02:00
### Check if temp APT upgrade file exists
if [ -f " ${ APT_TMP_FILE } " ] ; then
return_apt_upgrade_present = "0"
debug_message " is_apt_upgrade_absent − \
2020-06-22 12:22:01 +02:00
APT upgrade seems available for this system."
2020-06-22 20:46:37 +02:00
else
return_apt_upgrade_present = "1"
debug_message " is_apt_upgrade_absent − \
2020-06-22 12:22:01 +02:00
NO APT upgrade available for this system."
fi
return " ${ return_apt_upgrade_present } "
}
# }}}
is_maco_upgrade_present( ) { # {{{
## No pending upgrades by default
return_maco_upgrade_present = "1"
2020-06-22 20:46:37 +02:00
## Check if temp Maco upgrade file is present
if [ -f " ${ MACO_TMP_FILE } " ] ; then
return_maco_upgrade_present = "0"
debug_message " is_maco_upgrade_present − \
2020-06-22 12:22:01 +02:00
Maco upgrade seems available."
2020-06-22 20:46:37 +02:00
## Check if temp Maco urgent upgrade file is present
elif [ -f " ${ MACO_TMP_URGENT_FILE } " ] ; then
return_maco_upgrade_present = "0"
debug_message " is_maco_upgrade_present − \
2020-06-22 12:22:01 +02:00
Maco urgent upgrade seems available."
2020-06-22 20:46:37 +02:00
else
debug_message " is_maco_upgrade_present − \
2020-06-22 12:22:01 +02:00
No Maco upgrade require."
fi
return " ${ return_maco_upgrade_present } "
2021-01-06 11:52:24 +01:00
}
# }}}
is_maco_status_ok( ) { # {{{
## Maco status not ok by default
return_maco_status_ok = "1"
## Check if Maco status file is present
2021-01-06 13:35:52 +01:00
if [ -f " ${ MACO_STATUS_FILE } " ] ; then
2021-01-06 11:52:24 +01:00
debug_message " is_maco_status_ok − \
Maco status file ( ${ MACO_STATUS_FILE } ) exists."
local_maco_status = $( grep --max-count= 1 -- MacoStatus " ${ MACO_STATUS_FILE } " | cut --delimiter= "=" --fields= 2)
## Check current Maco status
if [ " ${ local_maco_status } " = "last-update-succeeded" ] ; then
debug_message " is_maco_status_ok − \
Last Maco upgrade succeed ( ${ local_maco_status } ) ."
return_maco_status_ok = "0"
else
debug_message " is_maco_status_ok − \
Maco require upgrade/maintenance ( current state: ${ local_maco_status } ) ."
fi
else
debug_message " is_maco_status_ok − \
Maco status file ( ${ MACO_STATUS_FILE } ) doesn' t exists."
fi
return " ${ return_maco_status_ok } "
2020-07-06 11:30:24 +02:00
}
# }}}
is_proc_running( ) { # {{{
local_proc_pattern = " ${ 1 } "
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_running = "1"
; ;
* ) ## At least one proc seems running
return_proc_running = "0"
; ;
esac
## Simple debug message to valid current variables
debug_message " is_proc_running − \
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_running } "
2021-11-24 07:35:44 +01:00
}
# }}}
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 } "
2020-07-06 15:07:23 +02:00
}
# }}}
2021-01-06 11:52:24 +01:00
is_file_present( ) { # {{{
2020-07-06 15:07:23 +02:00
2020-07-06 16:16:25 +02:00
local_file_present = " ${ 1 } "
2020-07-06 15:07:23 +02:00
## File doesn't exist by default
return_is_file_present = "1"
### Check if the file exists
2020-07-06 15:30:32 +02:00
# shellcheck disable=SC2086
2020-07-06 16:16:25 +02:00
if find ${ local_file_present } > /dev/null 2>& 1; then
2020-07-06 15:07:23 +02:00
return_is_file_present = "0"
debug_message " is_file_present − \
2020-07-06 16:16:25 +02:00
The file ${ RED } ${ local_file_present } ${ COLOR_DEBUG } exists."
2020-07-06 15:07:23 +02:00
else
return_is_file_present = "1"
debug_message " is_file_present − \
2020-07-06 16:16:25 +02:00
The file ${ RED } ${ local_file_present } ${ COLOR_DEBUG } doesn' t exist."
2020-07-06 15:07:23 +02:00
fi
return " ${ return_is_file_present } "
2020-07-06 16:16:25 +02:00
}
# }}}
2021-01-06 11:52:24 +01:00
is_file_absent( ) { # {{{
2020-07-06 16:16:25 +02:00
local_file_absent = " ${ 1 } "
## File exists by default
return_is_file_absent = "1"
### Check if the file exists
# shellcheck disable=SC2086
if find ${ local_file_absent } > /dev/null 2>& 1; then
return_is_file_absent = "1"
debug_message " is_file_absent − \
The file ${ RED } ${ local_file_absent } ${ COLOR_DEBUG } exists."
else
return_is_file_absent = "0"
debug_message " is_file_absent − \
The file ${ RED } ${ local_file_absent } ${ COLOR_DEBUG } doesn' t exist."
fi
return " ${ return_is_file_absent } "
2020-06-22 12:22:01 +02:00
}
# }}}
is_queue_enable( ) { # {{{
2020-06-22 11:33:31 +02:00
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_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_queue_enable_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_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_queue_enable_name : =/dev/null } ${ COLOR_DEBUG } \
state is: ${ RED } ${ local_sge_queue_state : =/dev/null } ${ COLOR_DEBUG } ."
return " ${ return_queue_enable } "
}
# }}}
is_queue_disable( ) { # {{{
local_queue_disable_hostname = " ${ 1 } "
local_queue_disable_name = " ${ 2 } "
## List all queues with 'disable' state and filter to the expected queue name
## add a fake_user to avoid pending jobs for this queue
### And count returned lines
local_queue_disable_test = $( qstat -f -qs d -q " ${ local_queue_disable_name : =/dev/null } @ ${ local_queue_disable_hostname : =/dev/null } " -u fake_user \
| wc -l)
case " ${ local_queue_disable_test } " in
0 ) ## No result so the queue is enable
local_sge_queue_state = "enable"
return_queue_disable = "1"
2020-06-22 17:12:14 +02:00
## Ensure to remove any previously setted file
2021-01-28 11:27:19 +01:00
# shellcheck disable=SC2086
find ${ sge_queue_flag_file } -delete
2020-06-22 11:33:31 +02:00
; ;
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_queue_disable_name : =/dev/null } @ ${ local_queue_disable_hostname : =/dev/null } queue (command return ${ local_queue_disable_test } lines). ${ RESET } "
exit 3
; ;
esac
## Simple debug message to valid current variables
debug_message " is_queue_disable − \
SGE queue: ${ RED } ${ local_queue_disable_name : =/dev/null } ${ COLOR_DEBUG } \
state is: ${ RED } ${ local_sge_queue_state : =/dev/null } ${ COLOR_DEBUG } ."
return " ${ return_queue_disable } "
}
# }}}
2020-06-22 12:22:01 +02:00
is_all_queue_enable( ) { # {{{
2020-06-22 11:33:31 +02:00
local_all_queue_enable_hostname = " ${ 1 } "
local_all_queue_enable_name = " ${ 2 } "
## By default, all queues are enable
return_all_queue_enable = "0"
## Test all queues one by one
for loop_enable_queue in ${ local_all_queue_enable_name } ; do
### If a queue is not enable
#### Change the return value
is_queue_enable " ${ local_all_queue_enable_hostname } " " ${ loop_enable_queue } " \
|| return_all_queue_enable = "1"
done
return " ${ return_all_queue_enable } "
}
# }}}
2020-06-22 12:22:01 +02:00
enable_sge_queue( ) { # {{{
2020-06-22 11:33:31 +02:00
local_sge_hostname = " ${ 1 } "
local_sge_queue_name = " ${ 2 } "
2020-06-22 17:12:14 +02:00
## If the queue was previously disabled by another script OR if FORCE_MODE is enable
2020-07-06 16:19:11 +02:00
if [ -f " ${ sge_queue_flag_file } " ] || [ " ${ FORCE_MODE } " -eq "0" ] ; then
2020-06-22 13:25:34 +02:00
debug_message " enable_sge_queue − \
2020-06-22 17:12:14 +02:00
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 } ."
2020-06-22 13:25:34 +02:00
## SGE command to enable the queue
2020-06-24 10:39:45 +02:00
qmod --enable " ${ local_sge_queue_name } @ ${ local_sge_hostname } " > /dev/null \
&& message " Enable SGE queue: ${ RED } ${ local_sge_queue_name : =/dev/null } @ ${ local_sge_hostname : =/dev/null } ${ RESET } " \
2020-06-22 13:25:34 +02:00
&& return_enable_queue = " ${ ? } "
else
2020-06-22 17:12:14 +02:00
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). "
2020-06-22 13:25:34 +02:00
return_enable_queue = "1"
fi
2020-06-22 11:33:31 +02:00
return " ${ return_enable_queue } "
}
# }}}
main( ) { # {{{
2021-04-20 07:26:35 +02:00
## If SGE is not yet available on this host {{{
2021-01-26 18:23:01 +01:00
### Exit
is_sge_host \
|| exit 0
2021-04-20 07:26:35 +02:00
## }}}
2021-01-26 18:23:01 +01:00
2021-04-20 07:26:35 +02:00
## Test if SGE Master is reachable {{{
### If sge_master_uri wasn't defined (environment variable,…) {{{
if [ -z " ${ sge_master_uri } " ] ; then
## Use local host for sge_master_uri
sge_master_uri = "physix-master.ipr.univ-rennes1.fr"
fi
### }}}
### If sge_master_port wasn't defined (environment variable,…) {{{
if [ -z " ${ sge_master_port } " ] ; then
## Use local host for sge_master_port
sge_master_port = "6444"
fi
### }}}
2021-01-26 20:02:22 +01:00
2021-04-20 07:26:35 +02:00
### If SGE Master is not reachable from this host {{{
#### Exit
2021-03-11 14:50:25 +01:00
is_sge_master_available \
|| exit 0
2021-04-20 07:26:35 +02:00
### }}}
2021-03-11 14:50:25 +01:00
## }}}
2021-04-20 07:26:35 +02:00
## Define all vars according the selected options
define_vars
2021-11-18 11:58:30 +01:00
## If we need to watch for processes
if [ " ${ CHECK_PROCESS } " -eq "0" ] ; then
2021-11-23 17:14:48 +01:00
## If nothing related to SGE is currently running {{{
2021-11-24 07:35:44 +01:00
### First ensure that SGE queue(s) are really disable without creation of any flag file
### Wait few seconds
2021-11-18 11:58:30 +01:00
### Try to start the SGE execd systemd service
2021-11-24 07:35:44 +01:00
### 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 } "
2021-11-23 17:14:48 +01:00
## }}}
2021-11-24 07:36:32 +01:00
## If anything related to SGE is still absent from the system {{{
### Exit with error if the service can't start
is_proc_absent " ${ sge_proc_pattern } " \
&& exit 4
## }}}
2021-11-18 11:58:30 +01:00
fi
2020-06-22 20:46:37 +02:00
## If we need to watch for upgrades
if [ " ${ CHECK_UPGRADE } " -eq "0" ] ; then
2021-11-23 17:14:48 +01:00
## If APT package upgrade is available {{{
2020-06-22 20:46:37 +02:00
### Exit (wait for APT upgrade to be applied)
is_apt_upgrade_present \
&& exit 0
2021-11-23 17:14:48 +01:00
## }}}
2020-06-22 20:46:37 +02:00
2021-11-23 17:14:48 +01:00
## If Maco upgrade is present {{{
2020-06-22 20:46:37 +02:00
### Exit (wait for Maco upgrade to be applied)
is_maco_upgrade_present \
&& exit 0
2021-11-23 17:14:48 +01:00
## }}}
2020-06-22 20:46:37 +02:00
fi
2020-06-22 12:22:01 +02:00
2021-11-23 17:14:48 +01:00
## If Maco status is ok, CONTINUE {{{
2021-01-06 11:52:24 +01:00
### Else Exit (wait for upgrade/maintenance)
is_maco_status_ok \
|| exit 0
2021-11-23 17:14:48 +01:00
## }}}
2021-01-06 11:52:24 +01:00
2020-07-06 17:05:06 +02:00
## If we need to watch for processes
if [ " ${ CHECK_PROCESS } " -eq "0" ] ; then
2021-11-23 17:14:48 +01:00
## If anything related to APT is currently running {{{
2020-07-06 15:07:23 +02:00
### Exit
2020-07-06 17:05:06 +02:00
is_proc_running " ${ apt_proc_pattern } " \
2020-07-06 15:07:23 +02:00
&& exit 0
2021-11-23 17:14:48 +01:00
## }}}
2020-07-06 16:16:25 +02:00
2021-11-23 17:14:48 +01:00
## If anything related to maco is currently running {{{
2020-07-06 16:16:25 +02:00
### Exit
2020-07-06 17:05:06 +02:00
is_proc_running " ${ maco_proc_pattern } " \
2020-07-06 16:37:30 +02:00
&& exit 0
2021-11-23 17:14:48 +01:00
## }}}
2020-07-06 15:07:23 +02:00
fi
2020-11-30 16:17:19 +01:00
## If we need to watch files
if [ " ${ CHECK_FILE } " -eq "0" ] ; then
2021-11-23 17:14:48 +01:00
## If nologin file exist (error on upgrade,…) {{{
2020-11-30 16:17:19 +01:00
### Exit
is_file_present " ${ file_nologin_path } " \
&& exit 0
2021-11-23 17:14:48 +01:00
## }}}
2020-11-30 16:17:19 +01:00
2021-11-23 17:14:48 +01:00
## If all SGE queue(s) were manually disabled (not any flag file) {{{
2020-11-30 16:17:19 +01:00
### Exit
is_file_absent " ${ sge_queue_flag_pattern } " \
&& exit 0
2021-11-23 17:14:48 +01:00
## }}}
2020-11-30 16:17:19 +01:00
fi
2020-06-22 11:33:31 +02:00
## Simple debug message with color to valid current variables
debug_message " main − Try to manage \
SGE queue( s) : ${ RED } ${ sge_queues_name_print : =/dev/null } ${ COLOR_DEBUG } \
for host: ${ RED } ${ sge_hostname : =/dev/null } ${ COLOR_DEBUG } ."
2021-11-23 17:14:48 +01:00
## If the queue(s) are already enable {{{
2020-07-06 16:26:55 +02:00
### Ensure to remove any potential flag file
2021-01-28 11:27:19 +01:00
# shellcheck disable=SC2086
2020-06-22 11:33:31 +02:00
### Exit
is_all_queue_enable " ${ sge_hostname } " " ${ sge_queues_name } " \
2021-01-28 11:27:19 +01:00
&& find ${ sge_queue_flag_pattern } -delete \
2020-06-22 11:33:31 +02:00
&& exit 0
2021-11-23 17:14:48 +01:00
## }}}
2020-06-22 11:33:31 +02:00
## Test all queues one by one
for loop_queue in ${ sge_queues_name } ; do
2020-06-22 17:12:14 +02:00
## File previously set if the queue was disabled by a script
## "automatically disabled" for an upgrade
2020-07-06 16:19:11 +02:00
sge_queue_flag_file = " ${ cluster_dir } /.sge. ${ loop_queue } .disable "
2020-06-22 17:12:14 +02:00
2021-11-23 17:14:48 +01:00
## If the queue is disable {{{
2020-06-22 11:33:31 +02:00
### Try to enable it
is_queue_disable " ${ sge_hostname } " " ${ loop_queue } " \
&& enable_sge_queue " ${ sge_hostname } " " ${ loop_queue } "
2021-11-23 17:14:48 +01:00
## }}}
2020-06-22 11:33:31 +02:00
2021-11-23 17:14:48 +01:00
## Don't consider manually disabled queue as an error except if FORCE_MODE was specified {{{
2020-07-06 16:19:11 +02:00
if [ -f " ${ sge_queue_flag_file } " ] || [ " ${ FORCE_MODE } " -eq "0" ] ; then
2020-06-22 17:12:14 +02:00
## 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 } " \
2020-07-06 17:19:07 +02:00
&& exit 5
2020-06-22 17:12:14 +02:00
fi
2021-11-23 17:14:48 +01:00
## }}}
2020-06-22 11:33:31 +02:00
done
}
# }}}
2020-06-22 13:48:26 +02:00
# Manage arguments # {{{
# This code can't be in a function due to arguments
if [ ! " ${ NBARGS } " -eq "0" ] ; then
manage_arg = "0"
## If the first argument is not an option
2020-06-22 18:23:22 +02:00
if ! printf -- '%s' " ${ 1 } " | grep -q -E -- "^-+" ;
2020-06-22 13:48:26 +02:00
then
## Use this argument for sge_hostname
sge_hostname = " ${ 1 } "
2020-06-22 14:20:45 +02:00
## Switch to the next argument
2020-06-22 13:48:26 +02:00
shift
manage_arg = $(( manage_arg+1))
fi
# Parse all options (start with a "-") one by one
2020-06-22 18:23:22 +02:00
while printf -- '%s' " ${ 1 } " | grep -q -E -- "^-+" ; do
2020-06-22 13:48:26 +02:00
case " ${ 1 } " in
2020-06-22 14:20:45 +02:00
-d| --debug ) ## debug
DEBUG = 0
; ;
2020-06-22 17:12:14 +02:00
-f| --force ) ## Force to enable SGE queue
FORCE_MODE = 0
; ;
2020-06-22 14:20:45 +02:00
--help ) ## help
2020-06-22 13:48:26 +02:00
usage
## Exit after help informations
exit 0
; ;
2020-06-22 14:20:45 +02:00
-h| --host| --hostname ) ## Specify a different host to manage
## Move to the next argument
shift
## Override previous definition of sge_hostname
sge_hostname = " ${ 1 } "
2020-06-22 14:04:57 +02:00
; ;
2020-06-22 14:20:45 +02:00
-q| --quiet ) ## Silent mode
2020-06-22 14:04:57 +02:00
## Avoid to display any message on standard output
OUTPUT_MESSAGE = 1
2020-06-22 13:48:26 +02:00
; ;
2020-06-22 14:20:45 +02:00
-- ) ## End of options list
2020-06-22 13:48:26 +02:00
## End the while loop
break
; ;
2020-06-22 14:20:45 +02:00
* ) ## unknow option
2020-06-22 13:48:26 +02:00
printf '%b\n' " ${ RED } Invalid option: ${ 1 } ${ RESET } "
printf '%b\n' "---"
usage
exit 1
; ;
esac
debug_message " Arguments management − \
${ RED } ${ 1 } ${ COLOR_DEBUG } option managed."
2020-06-22 14:20:45 +02:00
## Move to the next argument
2020-06-22 13:48:26 +02:00
shift
manage_arg = $(( manage_arg+1))
done
debug_message " Arguments management − \
${ RED } ${ manage_arg } ${ COLOR_DEBUG } argument( s) successfully managed."
else
debug_message " Arguments management − \
No arguments/options to manage."
fi
# }}}
2020-06-22 11:33:31 +02:00
main
exit 0