Commit c0d64342 authored by Maarten Litmaath's avatar Maarten Litmaath
Browse files

v1.9:

- The start command now adds a check cron job per service.
- The stop command removes that cron job.
- The cron job skips out when a file ~/no_check_${service} exists.
- Some code cleanup and cosmetic changes.
parent 6c0f919c
#!/bin/bash
# JAliEn VObox Startup Scripts - CE
# v1.4 - 2021-09-27
# v1.9 - 2021-10-30
# Authors:
# Kalana Dananjaya <kwijethu@cern.ch>
# Costin Grigoras <Costin.Grigoras@cern.ch>
......@@ -16,7 +16,7 @@ export JALIEN_CONF_DIR=${JALIEN_CONF_DIR:-$HOME/.j/config}
########################################################################################
# Write log to file
# Globals:
# setupLogFile: Log file for MonaLisa setup
# setupLogFile: Log file for CE setup
# Arguments:
# $1: String to log
########################################################################################
......@@ -30,6 +30,12 @@ function write_log() {
# ceClassName : Computing Element classname
########################################################################################
function stop_ce() {
#
# first prevent cron from restarting the CE...
#
manage_crontab remove ce
echo "Stopping JAliEn CE..."
pkill -TERM -f $ceClassName
sleep 3
......@@ -70,7 +76,7 @@ function check_liveness_ce() {
########################################################################################
# Check CE status
# Arguments:
# $command: "status" or "mlstatus"
# $command: "status" or "mlstatus"
# Returns:
# 0 if process is running, else 1
########################################################################################
......@@ -141,21 +147,11 @@ function status_ce() {
}
########################################################################################
# Start MonaLisa
# Start CE
# Globals:
# hostConfiguration: Associative array of host configuration parameters in LDAP
# commonConfiguration: Associative array of JAliEn local configuration parameters
# Arguments:
# confDir: AliEn configuration directory
# ldapHostname: LDAP hostname
# ldapPort: LDAP port
# hostname: Site hostname
# TBD
########################################################################################
function start_ce() {
confDir=$1
ldapHostname=$2
ldapPort=$3
hostname=$4
nl='
'
nl=${nl:0:1}
......@@ -166,6 +162,8 @@ function start_ce() {
return 0
fi
echo "Configuring the JAliEn CE..."
#
# Obtain host configuration from LDAP
#
......@@ -298,33 +296,65 @@ function start_ce() {
logFile="$logDir/CE-jvm-$(date '+%y%m%d-%H%M%S')-$$-log.txt"
echo -e "Starting JAliEn CE..."
echo "Starting the JAliEn CE..."
(
#
# In a subshell, to get the process detached from the parent
# change environment and directory only in this subshell...
#
source $envFile
cd $logDir
nohup jalien $ceClassName > "$logFile" 2>&1 < /dev/null &
echo $! > "$pidFile"
)
#
# Let cron watch over the CE...
#
# NOTE: for a local installation it is crucial that
# the code has not changed directory in this shell !
#
manage_crontab 3-53/10 ce
sleep 3
status_ce
}
########################################################################################
# Check CE
# Globals:
# checkLog : the logfile for the check results
########################################################################################
function check_ce() {
(
echo "=== START `date` PID $$"
if [ -e ~/no_check_ce ]
then
echo "Not checking the CE"
else
status_ce || start_ce
fi
echo "=== READY `date` PID $$"
) >> $checkLog 2>&1 < /dev/null
}
########################################################################################
# Run command
# Arguments:
# command to execute
########################################################################################
function run_ce() {
command=$1
if [[ $command = "start" ]]
then
confDir=$2
ldapHostname=$3
ldapPort=$4
hostname=$5
start_ce $confDir $ldapHostname $ldapPort $hostname
start_ce
elif [[ $command = "stop" ]]
then
......@@ -333,14 +363,18 @@ function run_ce() {
elif [[ $command = "restart" ]]
then
stop_ce
start_ce $confDir $ldapHostname $ldapPort $hostname
sleep 3
start_ce
elif [[ $command =~ "status" ]]
then
status_ce $command
elif [[ $command = "check" ]]
then
check_ce
else
echo "Command must be one of: 'start', 'stop', 'restart' or '(ml)status'"
echo "Error: unknown command: $command" >&2
return 2
fi
}
#!/bin/bash
# JAliEn VObox Startup Scripts - wrapper
# v1.2 - 2021-09-18
# v1.9 - 2021-10-30
# Authors:
# Kalana Dananjaya <kwijethu@cern.ch>
# Costin Grigoras <Costin.Grigoras@cern.ch>
......@@ -11,13 +11,14 @@ ldapHostname="alice-ldap.cern.ch"
ldapPort="8389"
hostname=`hostname -f`
confDir="${HOME}/.alien/config"
checkLog=/tmp/vobox-check-`date +%y%m%d`.log
dir="$(cd `dirname -- "$0"` &>/dev/null && pwd)"
source $dir/jalien-ce.sh
source $dir/monalisa.sh
cmds='start status stop restart mlstatus'
cmds='start status stop restart mlstatus check'
svcs='ce monalisa'
usage()
......@@ -32,6 +33,83 @@ usage()
exit 2
}
cron_job()
{
if [ $# -lt 1 ] || [ $# -gt 2 ]
then
echo "Usage: ${FUNCNAME[0]} remove_pattern [ cron-entry-string ]" >&2
return 2
fi
local rm_pat=$1
local entry=$2
crontab -l > /dev/null || return
(
crontab -l | egrep -v -e "$rm_pat"
[ ${entry:+x} ] && printf '%s\n' "$entry"
) | crontab
}
manage_crontab()
{
usage="Usage: ${FUNCNAME[0]} { minute_spec | remove } service"
case $1 in
*[0-9]*)
if [ "x${1/[^-0-9,\/}" != "x$1" ]
then
echo "Error: bad minute specifier: $1" >&2
echo "$usage" >&2
return 2
fi
local min=$1
;;
remove)
local min=
;;
*)
echo "$usage" >&2
return 2
esac
case " $svcs " in
*" $2 "*)
local svc=$2
;;
*)
echo "Error: unsupported service: $2" >&2
echo "Supported services are: $svcs" >&2
echo "$usage" >&2
return 2
esac
case $0 in
/*)
local cmd=$0
;;
./*)
local cmd=$PWD${0#.}
;;
*)
local cmd=$PWD/$0
esac
local entry=
if [ ${min:+x} ]
then
entry="$min * * * * /bin/sh $cmd check $svc > /dev/null 2>&1 < /dev/null"
fi
cron_job "${cmd##*/} check $svc" "$entry"
}
for cmd in $cmds
do
[[ "$1" = $cmd ]] && break
......@@ -52,12 +130,11 @@ for svc in ${2:-$svcs}
do
if [[ $svc = "monalisa" ]]
then
(run_monalisa $cmd $confDir $ldapHostname $ldapPort $hostname) || rc=$?
(run_monalisa $cmd) || rc=$?
elif [[ $svc = "ce" ]]
then
(run_ce $cmd $confDir $ldapHostname $ldapPort $hostname) || rc=$?
(run_ce $cmd) || rc=$?
else
usage
fi
......
#!/bin/bash
# JAliEn VObox Startup Scripts - MonaLisa
# v1.8 - 2021-10-26
# v1.9 - 2021-10-30
# Authors:
# Kalana Dananjaya <kwijethu@cern.ch>
# Costin Grigoras <Costin.Grigoras@cern.ch>
......@@ -199,21 +199,20 @@ function start_ml(){
# Check if there is an existing instance
check_liveness_ml
if [[ $? == 0 ]]
then
echo "Existing instance of MonaLisa already running..." && exit 1
echo "MonaLisa already running"
return 0
fi
# ======================== Config generation from LDAP ========================
confDir=$1
ldapHostname=$2
ldapPort=$3
hostname=$4
nl='
'
nl=${nl:0:1}
# Obtain site related configurations from LDAP
echo "Configuring MonaLisa..."
# ==================== Config generation from LDAP ====================
ldapBase="ou=Sites,o=alice,dc=cern,dc=ch"
ldapFilter="(&(objectClass=AliEnHostConfig)(host=$hostname))"
......@@ -432,32 +431,43 @@ function start_ml(){
echo "export MonaLisa_HOME=$monalisaDir/$monalisaVersion;" >> $envFile
fi
source $envFile
(
#
# change environment and directory only in this subshell...
#
source $envFile
farmHome=${MonaLisa_HOME}
farmHome=${MonaLisa_HOME}
if [[ -z $farmHome ]]
then
echo "Please point MonaLisa_HOME to the MonaLisa package location,"
echo "possibly by defining it in the version.properties file"
exit 1
fi
if [[ -z $farmHome ]]
then
echo "Please point MonaLisa_HOME to the MonaLisa package location,"
echo "possibly by defining it in the version.properties file"
exit 1
fi
# ======================== Start templating config files ======================
# ==================== Start templating config files ====================
echo "MonaLisa Log Directory: $logDir"
echo ""
echo "Started configuring MonaLisa..."
echo ""
setup $farmHome $logDir
setup $farmHome $logDir
echo "Starting MonaLisa...."
echo "Starting MonaLisa...."
(
# In a subshell, to ensure the process will be detached from the parent
cd $logDir
$farmHome/Service/CMD/ML_SER start < /dev/null
)
#
# Let cron watch over MonALISA...
#
# NOTE: for a local installation it is crucial that
# the code has not changed directory in this shell !
#
manage_crontab 7-57/10 monalisa
sleep 3
status_ml
}
########################################################################################
......@@ -465,6 +475,12 @@ function start_ml(){
########################################################################################
function stop_ml(){
#
# first prevent cron from restarting MonALISA...
#
manage_crontab remove monalisa
echo "Stopping MonaLisa..."
for pid in $(pgrep -u `id -u` -f -- '-DMonaLisa_HOME=')
......@@ -511,18 +527,42 @@ function status_ml() {
echo -e "MonaLisa$not Running"
fi
return $exit_code
}
########################################################################################
# Check MonaLisa
# Globals:
# checkLog : the logfile for the check results
########################################################################################
function check_ml() {
(
echo "=== START `date` PID $$"
if [ -e ~/no_check_monalisa ]
then
echo "Not checking MonALISA"
else
status_ml || start_ml
fi
echo "=== READY `date` PID $$"
) >> $checkLog 2>&1 < /dev/null
}
########################################################################################
# Run command
# Arguments:
# command to execute
########################################################################################
function run_monalisa() {
command=$1
if [[ $command = "start" ]]
then
confDir=$2
ldapHostname=$3
ldapPort=$4
hostname=$5
start_ml $confDir $ldapHostname $ldapPort $hostname
start_ml
elif [[ $command = "stop" ]]
then
......@@ -531,14 +571,20 @@ function run_monalisa() {
elif [[ $command = "restart" ]]
then
stop_ml
start_ml $confDir $ldapHostname $ldapPort $hostname
t=10
echo additional grace period of $t seconds...
sleep $t
start_ml
elif [[ $command =~ "status" ]]
then
status_ml $command
elif [[ $command = "check" ]]
then
check_ml
else
echo "Command must be one of: 'start', 'stop', 'restart' or 'mlstatus'"
echo "Error: unknown command: $command" >&2
return 2
fi
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment