Skip to content
Snippets Groups Projects
Commit c7693389 authored by Erik von Reis's avatar Erik von Reis
Browse files

rtcds: read in environment before setting flags and change flag tests to...

rtcds: read in environment before setting flags and change flag tests to explictly look for non-empty strings.

The entire block of code for initializing environment variables has been moved before the command line flag checks.
The USERLAND_FLAG and NO_KERNELSPACE_FLAG default values are determined by the environment, but the /etc/advligorts files need to be read in first.

Command line flags are cleared if empty string, or set if not empty.  This wasn't obvious originally since the test for flags was
just [[ $SOME_FLAG ]].

The tests have been changed to [[ -n $SOME_FLAG ]] or in the negative case [[ -z $SOME_FLAG ]].
This doesn't change the behavior but is less ambigous to the eye.
parent 56fedfe0
No related branches found
No related tags found
1 merge request!195Rtcds check model
......@@ -4,16 +4,77 @@ log() {
echo "$@" >&2
}
RTS_VERSION=${RTS_VERSION:-__VERSION__}
if [[ "$RTS_VERSION" =~ ._VERSION_. ]] ; then
log "RTS_VERSION variable not set."
exit 1
fi
# this should define all USER_VARS (see below)
ENV_FILE=${RTS_ENV:-/etc/advligorts/env}
HOST_ENV_FILE=/etc/advligorts/systemd_env_`hostname`
set -o allexport
source "$ENV_FILE" 2>/dev/null || true
if [[ -e $HOST_ENV_FILE ]] ; then
log "found host specific environment file '$HOST_ENV_FILE'"
source $HOST_ENV_FILE 2>/dev/null || true
fi
set +o allexport
SITE=${SITE^^*}
site=${SITE,,*}
IFO=${IFO^^*}
ifo=${IFO,,*}
CHECK_MODEL_IN_HOST=${CHECK_MODEL_IN_HOST:-false}
IS_DOLPHIN_NODE=${IS_DOLPHIN_NODE:-false}
DAQ_STREAMING=${DAQ_STREAMING:-false}
RCG_SRC=${RCG_SRC:-/usr/share/advligorts/src}
RCG_BUILD_ROOT=${RCG_BUILD_ROOT:-/var/cache/advligorts}
RCG_BUILDD=${RCG_BUILDD:-$RCG_BUILD_ROOT/rcg-$RTS_VERSION}
# FIXME: the RCG hard-codes /opt/rtcds as the root
RCG_TARGET=/opt/rtcds/${site}/${ifo}
# search paths for C source code
CDS_SRC=${CDS_SRC:-$RCG_LIB_PATH}
CDS_IFO_SRC=${CDS_IFO_SRC:-$CDS_SRC}
# add RCG module source to lib path
# FIXME: rename RCG_MOD_PATH
RCG_LIB_PATH=$RCG_LIB_PATH:${RCG_SRC}/src/epics/simLink/:${RCG_SRC}/src/epics/simLink/lib
#options from environment variables
ALLOW_MODEL_ENABLE=${ALLOW_MODEL_ENABLE:-true}
USER_VARS=(SITE IFO RCG_LIB_PATH)
LIST_VARS=(RTS_VERSION ${USER_VARS[@]} RCG_SRC RCG_BUILD_ROOT RCG_BUILDD RCG_TARGET)
EXPORT_VARS=(${USER_VARS[@]} site ifo CDS_SRC CDS_IFO_SRC)
# set the umask to ensure that all files and directories are made
# group writable
umask 0002
USE_KERNEL_MODELS=${USE_KERNEL_MODELS:-false}
# for all flags, empty string means cleared. Any other string means set.
if $USE_KERNEL_MODELS ; then
log "Build kernel-mode models by default"
USERLAND_FLAG=
NOKERNELSPACE_FLAG=
else
log "Build user mode models by default"
USERLAND_FLAG=0
NOKERNELSPACE_FLAG=0
fi
ALL_FLAG=
FOLLOW_FLAG=
INFO_FLAG=
VERSION_FLAG=
HELP_FLAG=
FORCE_START_FLAG=
# capture all command line flags as variables
params=""
ccmd=""
......@@ -72,57 +133,6 @@ done
eval set -- "$params"
RTS_VERSION=${RTS_VERSION:-__VERSION__}
if [[ "$RTS_VERSION" =~ ._VERSION_. ]] ; then
log "RTS_VERSION variable not set."
exit 1
fi
# this should define all USER_VARS (see below)
ENV_FILE=${RTS_ENV:-/etc/advligorts/env}
HOST_ENV_FILE=/etc/advligorts/systemd_env_`hostname`
set -o allexport
source "$ENV_FILE" 2>/dev/null || true
if [[ -e $HOST_ENV_FILE ]] ; then
log "found host specific environment file '$HOST_ENV_FILE'"
source $HOST_ENV_FILE 2>/dev/null || true
fi
set +o allexport
SITE=${SITE^^*}
site=${SITE,,*}
IFO=${IFO^^*}
ifo=${IFO,,*}
CHECK_MODEL_IN_HOST=${CHECK_MODEL_IN_HOST:-false}
IS_DOLPHIN_NODE=${IS_DOLPHIN_NODE:-false}
DAQ_STREAMING=${DAQ_STREAMING:-false}
RCG_SRC=${RCG_SRC:-/usr/share/advligorts/src}
RCG_BUILD_ROOT=${RCG_BUILD_ROOT:-/var/cache/advligorts}
RCG_BUILDD=${RCG_BUILDD:-$RCG_BUILD_ROOT/rcg-$RTS_VERSION}
# FIXME: the RCG hard-codes /opt/rtcds as the root
RCG_TARGET=/opt/rtcds/${site}/${ifo}
# search paths for C source code
CDS_SRC=${CDS_SRC:-$RCG_LIB_PATH}
CDS_IFO_SRC=${CDS_IFO_SRC:-$CDS_SRC}
# add RCG module source to lib path
# FIXME: rename RCG_MOD_PATH
RCG_LIB_PATH=$RCG_LIB_PATH:${RCG_SRC}/src/epics/simLink/:${RCG_SRC}/src/epics/simLink/lib
#options from environment variables
ALLOW_MODEL_ENABLE=${ALLOW_MODEL_ENABLE:-true}
USER_VARS=(SITE IFO RCG_LIB_PATH)
LIST_VARS=(RTS_VERSION ${USER_VARS[@]} RCG_SRC RCG_BUILD_ROOT RCG_BUILDD RCG_TARGET)
EXPORT_VARS=(${USER_VARS[@]} site ifo CDS_SRC CDS_IFO_SRC)
# set the umask to ensure that all files and directories are made
# group writable
umask 0002
##################################################
contains() {
......@@ -216,7 +226,7 @@ list_host_sys() {
# returns 0 if $1 names a system that's designated to run
# on this host
check_sys_in_host() {
if $CHECK_MODEL_IN_HOST && ! [[ $FORCE_START_FLAG ]] ; then
if $CHECK_MODEL_IN_HOST && [[ -z $FORCE_START_FLAG ]] ; then
local systems=`list_host_sys`
contains $1 $systems
fi
......@@ -265,10 +275,10 @@ check_host_sys_inactive() {
setup_make_args() {
make_args=''
if [[ $USERLAND_FLAG ]] ; then
if [[ -n $USERLAND_FLAG ]] ; then
make_args='RCG_BUILD_USP=YES'
fi
if [[ $NOKERNELSPACE_FLAG ]] ; then
if [[ -n $NOKERNELSPACE_FLAG ]] ; then
make_args="$make_args RCG_BUILD_NO_KOBJ=YES"
fi
}
......@@ -550,12 +560,12 @@ Available commands:
"
}
if [[ $HELP_FLAG ]]; then
if [[ -n $HELP_FLAG ]]; then
usage
exit 0
fi
if [[ $VERSION_FLAG ]] ; then
if [[ -n $VERSION_FLAG ]] ; then
echo $RTS_VERSION
exit 0
fi
......@@ -573,7 +583,7 @@ fi
case $cmd in
'build'|'make')
if [[ $ALL_FLAG ]] ; then
if [[ -n $ALL_FLAG ]] ; then
check_env
prep_buildd
build_world
......@@ -587,7 +597,7 @@ case $cmd in
fi
;;
'install')
if [[ $ALL_FLAG ]] ; then
if [[ -n $ALL_FLAG ]] ; then
check_env
prep_target
install_world
......@@ -601,7 +611,7 @@ case $cmd in
fi
;;
'start')
if [[ $ALL_FLAG ]] ; then
if [[ -n $ALL_FLAG ]] ; then
start_sys $(list_host_sys)
elif [[ $1 ]] ; then
check_host_sys_inactive $@
......@@ -612,7 +622,7 @@ case $cmd in
fi
;;
'restart')
if [[ $ALL_FLAG ]] ; then
if [[ -n $ALL_FLAG ]] ; then
# we do this in reverse so the IOP is stopped last
stop_sys $(list_host_sys | tac)
start_sys $(list_host_sys)
......@@ -626,7 +636,7 @@ case $cmd in
fi
;;
'stop'|'kill')
if [[ $ALL_FLAG ]] ; then
if [[ -n $ALL_FLAG ]] ; then
# we do this in reverse so the IOP is stopped last
stop_sys $(list_host_sys | tac)
elif [[ $1 ]] ; then
......@@ -643,7 +653,7 @@ case $cmd in
log "ALLOW_MODEL_ENABLE environment variable is set to false."
exit 2
fi
if [[ $ALL_FLAG ]] ; then
if [[ -n $ALL_FLAG ]] ; then
# we do this in reverse so the IOP is stopped last
${cmd}_sys $(list_host_sys | tac)
elif [[ $1 ]] ; then
......@@ -654,7 +664,7 @@ case $cmd in
fi
;;
'status')
if [ -z "$1" ] || [[ $ALL_FLAG ]] ; then
if [ -z "$1" ] || [[ -n $ALL_FLAG ]] ; then
global_status
else
sys=$1
......@@ -663,7 +673,7 @@ case $cmd in
;;
'log')
args=
if [[ $FOLLOW_FLAG ]] ; then
if [[ -n $FOLLOW_FLAG ]] ; then
args="-f"
fi
if [ -z "$1" ] ; then
......@@ -675,7 +685,7 @@ case $cmd in
;;
'blog')
format=full
if [[ $INFO_FLAG ]] ; then
if [[ -n $INFO_FLAG ]] ; then
format=info
fi
if [ -z "$1" ] ; then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment