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

v1.4:

- jalien_ce.sh: better variable names for host configuration.
- jalien_vobox_services: first version.
- monalisa.sh: various fixes and enhancements:
* better variable names for host configuration;
* added site configuration;
* fixed typos;
* do not split configuration lines on embedded white space;
* configure the new jalien_vobox_services sensor script;
* cosmetic changes.
parent 441ca512
#!/bin/bash
# JAliEn VObox Startup Scripts - CE
# v1.3 - 2021-09-19
# v1.4 - 2021-09-27
# Authors:
# Kalana Dananjaya <kwijethu@cern.ch>
# Costin Grigoras <Costin.Grigoras@cern.ch>
......@@ -143,7 +143,7 @@ function status_ce() {
########################################################################################
# Start MonaLisa
# Globals:
# siteConfiguration: Associative array of site configuration parameters in LDAP
# hostConfiguration: Associative array of host configuration parameters in LDAP
# commonConfiguration: Associative array of JAliEn local configuration parameters
# Arguments:
# confDir: AliEn configuration directory
......@@ -167,18 +167,18 @@ function start_ce() {
fi
#
# Obtain site configuration from LDAP
# Obtain host configuration from LDAP
#
ldapBase="ou=Sites,o=alice,dc=cern,dc=ch"
ldapFilter="(&(objectClass=AliEnHostConfig)(host=$hostname))"
siteLDAPQuery=$(
hostLDAPQuery=$(
ldapsearch -x -LLL -h $ldapHostname -p $ldapPort -b $ldapBase "$ldapFilter" |
perl -p00e 's/\n //g' | envsubst
)
declare -A siteConfiguration
declare -A hostConfiguration
while IFS= read -r line
do
......@@ -192,14 +192,14 @@ function start_ce() {
val=$(echo "$line" | cut -d ":" -f 2- | sed s/.//)
key=${key^^}
prev=${siteConfiguration[$key]}
prev=${hostConfiguration[$key]}
prev=${prev:+$prev$nl}
siteConfiguration[$key]=$prev$val
hostConfiguration[$key]=$prev$val
fi
done <<< "$siteLDAPQuery"
done <<< "$hostLDAPQuery"
baseLogDir=$(echo "${siteConfiguration[LOGDIR]}" | envsubst)
baseLogDir=$(echo "${hostConfiguration[LOGDIR]}" | envsubst)
if [[ -z $baseLogDir ]]
then
......
#!/bin/bash
# JAliEn VObox Startup Scripts - MonaLisa
# v1.2 - 2021-09-18
# v1.4 - 2021-09-27
# Authors:
# Kalana Dananjaya <kwijethu@cern.ch>
# Costin Grigoras <Costin.Grigoras@cern.ch>
# Maarten Litmaath <Maarten.Litmaath@cern.ch>
##############################################
########################################################################################
# Write log to file
# Globals:
# setupLogFile: Log file for MonaLisa setup
# Arguments:
# $1: String to log
###############################################
########################################################################################
function write_log(){
echo $1 >> $setupLogFile
}
####################################################################################
########################################################################################
# Templates a given configuration files(Add, delete or change content)
# Globals:
# add: Array of lines to add to file
......@@ -27,7 +27,7 @@ function write_log(){
# Arguments:
# srcFile: Source file
# destFile: Destination file
####################################################################################
########################################################################################
function template(){
srcFile=$1
......@@ -83,7 +83,7 @@ function template(){
}
#############################################################################################
########################################################################################
# Setup MonaLisa
# Globals:
# monalisaLDAPconfiguration: Associative array of MonaLisa configuration parameters in LDAP
......@@ -92,7 +92,7 @@ function template(){
# Arguments:
# farmHome: MonaLisa base package location
# logDir: MonaLisa log directory
#############################################################################################
########################################################################################
function setup() {
farmHome=$1
......@@ -105,39 +105,48 @@ function setup() {
# Copy base templates to the local directory
mkdir -p "$logDir/myFarm/"
# ===================================================================================
# ==============================================================================
# myFarm.conf
# Convert multi-valued attribute to array
while IFS= read -r line ; do add+=($line); done <<< "${siteConfiguration[MONALISA_ADDMODULES_LIST]}"
while IFS= read -r line
do
add+=("$line")
done <<< "${monalisaLDAPconfiguration[ADDMODULES]}"
add+=("^monLogTail{Cluster=AliEnServicesLogs,Node=CE,command=tail -n 15 -F $ceLogFile 2>&1}%3")
add+=("*AliEnServicesStatus{monStatusCmd, localhost, \"logDir=$baseLogDir $(cd `dirname -- "$0"` &>/dev/null && pwd)/jalien-vobox.sh mlstatus ce,timeout=800\"}%900")
cmd=/cvmfs/alice.cern.ch/scripts/vobox/jalien_vobox_services
add+=("*AliEnServicesStatus{monStatusCmd, localhost, \"logDir=$baseLogDir $cmd,timeout=800\"}%900")
template "$farmHome/Service/myFarm/myFarm.conf" "$logDir/myFarm/myFarm.conf"
# ========================================================================================
# ==============================================================================
# ml.properties
declare -Ag changes
# Convert multi-valued attribute to array
while IFS= read -r line ; do add+=($line); done <<< "${monalisaLDAPconfiguration[ADDPROPERTIES]}"
while IFS= read -r line
do
add+=("$line")
done <<< "${monalisaLDAPconfiguration[ADDPROPERTIES]}"
location=${monalisaLDAPconfiguration[LOCATION]-${monalisaLDAPconfiguration[SITE_LOCATION]}} || ""
country=${monalisaLDAPconfiguration[COUNTRY]-${monalisaLDAPconfiguration[SITE_COUNTRY]}} || ""
long=${monalisaLDAPconfiguration[LONGITUDE]-${monalisaLDAPconfiguration[SITE_LONGITUDE]}} || "N/A"
lat=${monalisaLDAPconfiguration[LATITUDE]-${monalisaLDAPconfiguration[SITE_LATITUDE]}} || "N/A"
admin=${monalisaLDAPconfiguration[ADMINISTRATOR]-${monalisaLDAPconfiguration[SITE_ADMINISTRATOR]}} || "N/A"
for attr in location country latitude longitude administrator
do
k=${attr^^}
eval "$attr=\${monalisaLDAPconfiguration[$k]:-\${siteConfiguration[$k]}}"
done
changes["^MonaLisa.Location.*"]="MonaLisa.Location=$location"
changes["^MonaLisa.Country.*"]="MonaLisa.Country=$country"
changes["^MonaLisa.LAT.*"]="MonaLisa.LAT=$lat"
changes["^MonaLisa.LONG.*"]="MonaLisa.LONG=$long"
changes["^MonaLisa.ContactEmail.*"]="MonaLisa.ContactEmail=$admin"
changes["^MonaLisa.LAT.*"]="MonaLisa.LAT=$latitude"
changes["^MonaLisa.LONG.*"]="MonaLisa.LONG=$longitude"
changes["^MonaLisa.ContactEmail.*"]="MonaLisa.ContactEmail=$administrator"
template "$farmHome/Service/myFarm/ml.properties" "$logDir/myFarm/ml.properties"
# ===================================================================================
# =============================================================================
# ml.env
declare -Ag changes
......@@ -148,18 +157,17 @@ function setup() {
template "$farmHome/Service/CMD/ml_env" "$logDir/myFarm/ml_env"
# ============================= Export variables =====================================
# ============================= Export variables ==============================
export CONFDIR="$logDir/myFarm"
export ALICE_LOGDIR=$baseLogDir
export JAVA_OPTS=${monalisaLDAPconfiguration[JAVAOPTS]}
# ===================================================================================
}
#####################################
########################################################################################
# MonaLisa liveness check
# Returns:
# 0 if process is running,else 1
#####################################
########################################################################################
function check_liveness_ml(){
pid=$(pgrep -n -u `id -u` -f -- "-DMonaLisa_HOME=")
......@@ -171,9 +179,10 @@ function check_liveness_ml(){
fi
}
#############################################################################################
########################################################################################
# Start MonaLisa
# Globals:
# hostConfiguration: Associative array of host configuration parameters in LDAP
# siteConfiguration: Associative array of site configuration parameters in LDAP
# monalisaLDAPconfiguration: Associative array of MonaLisa configuration parameters in LDAP
# commonConfiguration: Associative array of JAliEn local configuration parameters
......@@ -182,7 +191,7 @@ function check_liveness_ml(){
# ldapHostname: LDAP hostname
# ldapPort: LDAP port
# hostname: Site hostname
#############################################################################################
########################################################################################
function start_ml(){
# Check if there is an existing instance
......@@ -206,6 +215,33 @@ function start_ml(){
ldapBase="ou=Sites,o=alice,dc=cern,dc=ch"
ldapFilter="(&(objectClass=AliEnHostConfig)(host=$hostname))"
hostLDAPQuery=$(
ldapsearch -x -LLL -h $ldapHostname -p $ldapPort -b $ldapBase "$ldapFilter" |
perl -p00e 's/\n //g' | envsubst
)
declare -A hostConfiguration
while IFS= read -r line
do
if [[ ! -z $line ]]
then
key=$(echo "$line" | cut -d ":" -f 1 )
val=$(echo "$line" | cut -d ":" -f 2- | sed s/.//)
key=${key^^}
prev=${hostConfiguration[$key]}
prev=${prev:+$prev$nl}
hostConfiguration[$key]=$prev$val
fi
done <<< "$hostLDAPQuery"
parentSite=${hostConfiguration[DN]%,ou=Sites,*}
parentSite=${parentSite##*=}
ldapBase="ou=$parentSite,ou=Sites,o=alice,dc=cern,dc=ch"
ldapFilter="(&(objectClass=AliEnSite))"
siteLDAPQuery=$(
ldapsearch -x -LLL -h $ldapHostname -p $ldapPort -b $ldapBase "$ldapFilter" |
perl -p00e 's/\n //g' | envsubst
......@@ -215,7 +251,6 @@ function start_ml(){
while IFS= read -r line
do
#Ignore empty lines and create an associative array from ldap configuration
if [[ ! -z $line ]]
then
key=$(echo "$line" | cut -d ":" -f 1 )
......@@ -229,20 +264,12 @@ function start_ml(){
fi
done <<< "$siteLDAPQuery"
# Obtain MonAlisa service related configurations from LDAP
siteName=${siteConfiguration[MONALISA]}
if [[ -z $siteName ]]
then
echo "LDAP Configuration for MonaLisa not found. Please set it up and try again."
exit 1
fi
ldapBase="ou=Sites,o=alice,dc=cern,dc=ch"
ldapFilter="(&(objectClass=AliEnMonaLisa)(host=$hostname))"
monalisaLDAPQuery=$(
ldapsearch -x -LLL -h $ldapHostname -p $ldapPort -b $ldapBase "$ldapFilter" |
perl -p00e 's/\n //g' | envsubst
)
)
declare -A monalisaLDAPconfiguration
......@@ -262,15 +289,17 @@ function start_ml(){
fi
done <<< "$monalisaLDAPQuery"
parentSite=${monalisaLDAPconfiguration[DN]%,ou=Sites,*}
parentSite=${parentSite##*=}
case ${monalisaLDAPconfiguration[NAME]} in
'')
echo "LDAP Configuration for MonaLisa not found. Please set it up and try again."
exit 1
;;
LCG|LCG[-_]*)
monalisaLDAPconfiguration[NAME]=$parentSite${monalisaLDAPconfiguration[NAME]#LCG}
esac
baseLogDir=$(echo "${siteConfiguration[LOGDIR]}" | envsubst)
baseLogDir=$(echo "${hostConfiguration[LOGDIR]}" | envsubst)
if [[ -z $baseLogDir ]]
then
......@@ -295,12 +324,25 @@ function start_ml(){
> $setupLogFile
write_log "========== Site Config =========="
for x in "${!siteConfiguration[@]}"
do
printf "[%s]=%s\n" "$x" "${siteConfiguration[$x]}" >> $setupLogFile
done
write_log ""
write_log "========== VObox Config =========="
for x in "${!siteConfiguration[@]}"; do printf "[%s]=%s\n" "$x" "${siteConfiguration[$x]}" >> $setupLogFile ; done
for x in "${!hostConfiguration[@]}"
do
printf "[%s]=%s\n" "$x" "${hostConfiguration[$x]}" >> $setupLogFile
done
write_log ""
write_log "========== MonaLisa Config =========="
for x in "${!monalisaLDAPconfiguration[@]}"; do printf "[%s]=%s\n" "$x" "${monalisaLDAPconfiguration[$x]}" >> $setupLogFile ; done
for x in "${!monalisaLDAPconfiguration[@]}"
do
printf "[%s]=%s\n" "$x" "${monalisaLDAPconfiguration[$x]}" >> $setupLogFile
done
write_log ""
......@@ -377,15 +419,16 @@ function start_ml(){
source $envFile
farmHome=${MonaLisa_HOME} # MonaLisa package location should be defined as an environment variable or defined in version.properties file
farmHome=${MonaLisa_HOME}
if [[ -z $farmHome ]]
then
echo "Please point MonaLisa variable to the MonaLisa package location by setting the environment variable MonaLisa_HOME"
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 ""
......@@ -402,9 +445,9 @@ function start_ml(){
)
}
###################
########################################################################################
# Stop MonaLisa
###################
########################################################################################
function stop_ml(){
echo "Stopping MonaLisa..."
......@@ -431,13 +474,13 @@ function stop_ml(){
fi
}
###################################
########################################################################################
# Check MonaLisa status
# Arguments:
# $command: "status" or "mlstatus"
# Returns:
# 0 if process is running,else 1
###################################
########################################################################################
function status_ml() {
command=$1
......@@ -480,7 +523,7 @@ function run_monalisa() {
status_ml $command
else
echo "Command must be one of: 'start', 'stop', 'restart' or 'mlstatus'"
echo "Command must be one of: 'start', 'stop', 'restart' or 'mlstatus'"
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