diff --git a/README.md b/README.md
index e046e9c6..ba15634d 100644
--- a/README.md
+++ b/README.md
@@ -748,7 +748,8 @@ usage: restartdaq options
OPTIONS:
-w sort windows after start
-p select partition (same as used last)
- -s silent (do not email jana)
+ -s silent (do not email jana)
+ -C [cnf] : (FOR LCLS2 Hutches) Specify a CNF to run. E.g. qrix.py or crix.py
@@ -792,6 +793,7 @@ Sourcing this script lets ssh-agent set the proper environment variables it need
usage: startami options
we are starting another ami session here
+ This script restarts AMI1 in LCLS1 hutches and AMI2 in LCLS2 hutches
OPTIONS:
-s: stop the ami client current running on this machine
@@ -802,7 +804,8 @@ usage: startami options
stopami |
-Kill an AMI process running in the current hutch.
+Kill an AMI process running in the current hutch.
+This script stops AMI1 in LCLS1 hutches and AMI2 in LCLS2 hutches
|
diff --git a/scripts/daq_utils.py b/scripts/daq_utils.py
index 94ecfc6d..2629cf0b 100644
--- a/scripts/daq_utils.py
+++ b/scripts/daq_utils.py
@@ -92,7 +92,7 @@ def get_job_info(self):
class DaqManager:
- def __init__(self, verbose=False):
+ def __init__(self, verbose=False, cnf=None):
self.verbose = verbose
self.hutch = call_subprocess("get_info", "--gethutch")
if len(self.hutch) != 3:
@@ -101,7 +101,10 @@ def __init__(self, verbose=False):
self.user = self.hutch + "opr"
self.sbman = SbatchManager(self.user)
self.scripts_dir = f"/reg/g/pcds/dist/pds/{self.hutch}/scripts"
- self.cnf_file = f"{self.hutch}.py"
+ if cnf is None:
+ self.cnf_file = f"{self.hutch}.py"
+ else:
+ self.cnf_file = cnf
def isdaqmgr(self, quiet=False):
if self.hutch in DAQMGR_HUTCHES:
diff --git a/scripts/restartdaq b/scripts/restartdaq
index 54961624..2e819ab1 100755
--- a/scripts/restartdaq
+++ b/scripts/restartdaq
@@ -1,12 +1,5 @@
#!/bin/bash
-# Check if the current's user hutch uses daqmgr. If so,
-# use the python utilities to manage the daq.
-if [ "$(daqutils isdaqmgr)" = "true" ]; then
- daqutils $(basename "$0") $@
- exit 0
-fi
-
usage()
{
cat << EOF
@@ -18,6 +11,7 @@ OPTIONS:
-p select partition (same as used last)
-s silent (do not email jana)
-c enable core files
+-C (LCLS2 DAQMGR Hutches ONLY!) Select a cnf to use.
EOF
}
@@ -37,7 +31,7 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then
fi
CORESIZE=0
-while getopts "m:pwscd" OPTION
+while getopts "m:pwscdC:" OPTION
do
case $OPTION in
p)
@@ -55,6 +49,9 @@ do
c)
CORESIZE=2000000000
;;
+ C)
+ DAQMGR_CNF=$OPTARG
+ ;;
d)
DSSTEST=1
;;
@@ -66,6 +63,29 @@ do
esac
done
+# Check if the current's user hutch uses daqmgr. If so,
+# use the python utilities to manage the daq.
+if [ "$(daqutils isdaqmgr)" = "true" ]; then
+ if [[ -n "$DAQMGR_CNF" ]]; then
+ for arg in "$@"; do
+ shift
+ case $arg in
+ -C)
+ shift
+ shift
+ ;;
+ *)
+ set -- "$@"
+ ;;
+ esac
+ done
+ daqutils --cnf "$DAQMGR_CNF" "$(basename "$0")" "$@"
+ else
+ daqutils "$(basename "$0")" "$@"
+ fi
+ exit 0
+fi
+
if [[ $(whoami) != *'opr'* ]]; then
echo "Please run the DAQ from the operator account!"
exit
@@ -73,7 +93,7 @@ fi
HUTCH=$(get_info --gethutch)
CNFEXT=.cnf
-CNFFILE=$HUTCH$CNFEXT
+CNFFILE="$HUTCH""$CNFEXT"
if [ "$HOSTNAME" == 'cxi-daq' ]; then
PEXT=_0
CNFFILE=$HUTCH$PEXT$CNFEXT
@@ -96,6 +116,7 @@ cd /reg/g/pcds/dist/pds/"$HUTCH"/scripts/ || exit
DAQNETWORK='fez'
LCLS2_HUTCHES="rix, tmo, ued, txi"
if echo "$LCLS2_HUTCHES" | grep -iw "$HUTCH" > /dev/null; then
+ # shellcheck disable=SC1090
source /reg/g/pcds/dist/pds/"$HUTCH"/scripts/setup_env.sh
PROCMGR='procmgr'
DAQNETWORK='drp'
@@ -109,8 +130,7 @@ if [ "$IS_DAQ_HOST" == 0 ]; then
WORKINGHOSTS=''
#make sure at least cds is up.
for HOST in $HOSTS; do
- ping -w 2 "$HOST" >/dev/null 2>&1
- if [[ $? == 0 ]]; then
+ if [[ $(ping -w 2 "$HOST" >/dev/null 2>&1) == 0 ]]; then
WORKINGHOSTS=$WORKINGHOSTS' '$HOST
fi
done
@@ -125,12 +145,12 @@ else
DAQHOST=$(wheredaq)
fi
-PLATFORM=$(grep 'if not platform' /reg/g/pcds/dist/pds/"$HUTCH"/scripts/$CNFFILE | awk '{print $NF}' | sed s/\'//g)
+PLATFORM=$(grep 'if not platform' /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNFFILE" | awk '{print $NF}' | sed s/\'//g)
if [[ "$DAQHOST" != *$NOTRUNNING* ]]; then
echo stop the DAQ on "$DAQHOST" from "$HOSTNAME"
T="$(date +%s%N)"
$PROCMGR stop \
- /reg/g/pcds/dist/pds/"$HUTCH"/scripts/$CNFFILE
+ /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNFFILE"
if [ -f /reg/g/pcds/dist/pds/"$HUTCH"/scripts/p"$PLATFORM"$CNFEXT.running ]; then
@@ -146,7 +166,7 @@ else
echo while DAQ reports to not run, will stop the DAQ on "$DAQHOST" from "$HOSTNAME" to clear the p"$PLATFORM"$CNFEXT.running file
T="$(date +%s%N)"
$PROCMGR stop \
- /reg/g/pcds/dist/pds/"$HUTCH"/scripts/$CNFFILE
+ /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNFFILE"
if [ -f /reg/g/pcds/dist/pds/"$HUTCH"/scripts/p"$PLATFORM"$CNFEXT.running ]; then
echo 'the DAQ did not stop properly, exit now and try again follow the escalation procedure'
@@ -164,7 +184,7 @@ T="$(date +%s%N)"
echo start DAQ on "$AIMHOST"
if [ "$HOSTNAME" == "$AIMHOST" ]; then
$PROCMGR start \
- /reg/g/pcds/dist/pds/"$HUTCH"/scripts/$CNFFILE -c $CORESIZE -o /reg/g/pcds/pds/"$HUTCH"/logfiles
+ /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNFFILE" -c $CORESIZE -o /reg/g/pcds/pds/"$HUTCH"/logfiles
else
ssh -Y "$AIMHOST" restartdaq
fi
@@ -199,7 +219,7 @@ if [ ${#DOWIN} != 0 ] || [ ${#SELPART} != 0 ]; then
SELPART=0
fi
fi
- if [ -f /reg/neh/operator/"$HUTCH"\opr/bin/"$HUTCH"\_cleanup_windows_daq ]; then
+ if [ -f /reg/neh/operator/"$HUTCH"opr/bin/"$HUTCH"_cleanup_windows_daq ]; then
if [ ${#DOWIN} != 0 ]; then
echo 'This instrument does not have standard locations for DAQ windows setup'
fi
@@ -210,13 +230,13 @@ fi
if [ ${#DOWIN} != 0 ]; then
T="$(date +%s%N)"
if [ "$HUTCH" == 'xpp' ]; then
- test=$(xdotool search --sync --onlyvisible --name 'ProcStat')
+ xdotool search --sync --onlyvisible --name 'ProcStat'
fi
if [ "$HUTCH" == 'xcs' ]; then
sleep 2
fi
echo 'resorting the windows now using: /reg/neh/operator/'"$HUTCH"'opr/bin/'"$HUTCH"'_cleanup_windows_daq'
- /reg/neh/operator/"$HUTCH"\opr/bin/"$HUTCH"\_cleanup_windows_daq
+ /reg/neh/operator/"$HUTCH"opr/bin/"$HUTCH"_cleanup_windows_daq
Tdinter="$(($(date +%s%N)-T))"
Sinter="$((Tdinter/1000000000))"
Minter="$((Tdinter/1000000))"
diff --git a/scripts/run_daq_utils.py b/scripts/run_daq_utils.py
index cdb1d993..ba9e7b32 100644
--- a/scripts/run_daq_utils.py
+++ b/scripts/run_daq_utils.py
@@ -28,7 +28,7 @@ def isdaqmgr(daqmgr, args):
parser = argparse.ArgumentParser(prog="run_daq_utils", description=__doc__)
parser.add_argument("-v", "--verbose", action="store_false")
-
+ parser.add_argument("--cnf", default=None)
subparsers = parser.add_subparsers()
psr_restart = subparsers.add_parser(
"restartdaq",
@@ -55,5 +55,5 @@ def isdaqmgr(daqmgr, args):
args = parser.parse_args()
- daqmgr = DaqManager(args.verbose)
+ daqmgr = DaqManager(args.verbose, args.cnf)
args.func(daqmgr, args)
diff --git a/scripts/startami b/scripts/startami
index 7e906a65..1e5b9820 100755
--- a/scripts/startami
+++ b/scripts/startami
@@ -17,7 +17,6 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then
exit 0
fi
-STOP_AMI=0
while getopts "sc:" OPTION
do
case "$OPTION" in
@@ -33,23 +32,28 @@ do
;;
esac
done
-shift "$(($OPTIND-1))"
+shift "$((OPTIND-1))"
-if [[ `whoami` != *'opr'* ]]; then
+if [[ $(whoami) != *'opr'* ]]; then
echo "Please run ami from the operator account!"
exit
fi
-HUTCH=`get_hutch_name`
-EXPNAME=`get_curr_exp`
+HUTCH=$(get_hutch_name)
+if [ "$(daqutils isdaqmgr)" = "true" ]; then
+ daqutils --cnf "${HUTCH}"_ami.py restartdaq "$@"
+ exit 0
+fi
+
+EXPNAME=$(get_curr_exp)
CNFEXT=.cnf
-if [[ $HUTCH == 'cxi' ]]; then
- if [[ $HOSTNAME == 'cxi-daq' ]]; then
+if [[ "$HUTCH" == 'cxi' ]]; then
+ if [[ "$HOSTNAME" == 'cxi-daq' ]]; then
CNFEXT=_0.cnf
- elif [[ $HOSTNAME == 'cxi-monitor' ]]; then
+ elif [[ "$HOSTNAME" == 'cxi-monitor' ]]; then
CNFEXT=_1.cnf
- elif [[ -z $CONFIG ]]; then
+ elif [[ -z "$CONFIG" ]]; then
echo 'You must provide cxi config file (-c) if not on daq machine'
exit 1
fi
@@ -61,46 +65,46 @@ if [[ -z $CONFIG ]]; then
fi
#
-# this is XPP specific. Don't think we should have local plugins anyways,
-# only release ones.
+# this is XPP specific. Don't think we should have local plugins anyways,
+# only release ones.
#
source /reg/g/pcds/setup/pathmunge.sh
-if [ $HUTCH == 'xpp' ]; then
+if [ "$HUTCH" == 'xpp' ]; then
ldpathmunge /reg/neh/operator/xppopr/ami_plugins
-elif [ $HUTCH == 'xcs' ]; then
+elif [ "$HUTCH" == 'xcs' ]; then
ldpathmunge /reg/neh/operator/xcsopr/online/ami_plugins
fi
-DAQHOST=`wheredaq`
-ami_base_path=`grep ami_base_path /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG | grep -v '#' | grep -v 'ami_base_path+' | awk 'BEGIN { FS = "=" }; { print $2}' | sed s/\'//g`
-ami_path=$ami_base_path`grep ami_path /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG | grep -v 'ami_path+' | grep -v '#' | awk 'BEGIN { FS = "= " }; { print $2}' | sed s/ami_base_path+// | sed s/\'//g`
+DAQHOST=$(wheredaq)
+ami_base_path=$(grep ami_base_path /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" | grep -v '#' | grep -v 'ami_base_path+' | awk 'BEGIN { FS = "=" }; { print $2}' | sed s/\'//g)
+ami_path=$ami_base_path$(grep ami_path /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" | grep -v 'ami_path+' | grep -v '#' | awk 'BEGIN { FS = "= " }; { print $2}' | sed s/ami_base_path+// | sed s/\'//g)
-proxy_cds=`/reg/g/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr status /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG | grep ami_proxy | awk {'print $1'} | sed s/'-fez'/''/g`
+proxy_cds=$(/reg/g/pcds/dist/pds/"$HUTCH"/current/tools/procmgr/procmgr status /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" | grep ami_proxy | awk '{print $1}' | sed s/'-fez'/''/g)
-amicmd=`grep ami_client /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG | grep -v '#' | awk 'BEGIN { FS = ":" }; { print $4}' | sed s/ami_path//g | sed s/\'+proxy_cds/$proxy_cds/g | sed s:\'+expname:$EXPNAME/:g | sed s/+\'//g | sed s/\'\}\)//g`
+amicmd=$(grep ami_client /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" | grep -v '#' | awk 'BEGIN { FS = ":" }; { print $4}' | sed s/ami_path//g | sed s/\'+proxy_cds/"$proxy_cds"/g | sed s:\'+expname:"$EXPNAME"/:g | sed s/+\'//g | sed s/\'\}\)//g)
if [[ "$DAQHOST" == *"$HOSTNAME" ]]; then # Check host and daq host line share host name...
#running on the DAQ host, this will restart the ami_client!
- read -p "Do you really intend to restart the ami_client on $DAQHOST? (y/n)"
+ read -r -p "Do you really intend to restart the ami_client on $DAQHOST? (y/n)"
if [ "$REPLY" == "y" ];then
echo "Restarting the ami_client...";
- /reg/g/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr stop \
- /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG ami_client
- /reg/g/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr start \
- /reg/g/pcds/dist/pds/$HUTCH/scripts/$CONFIG -c 2000000000 -o /reg/g/pcds/pds/$HUTCH/logfiles ami_client
+ /reg/g/pcds/dist/pds/"$HUTCH"/current/tools/procmgr/procmgr stop \
+ /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" ami_client
+ /reg/g/pcds/dist/pds/"$HUTCH"/current/tools/procmgr/procmgr start \
+ /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CONFIG" -c 2000000000 -o /reg/g/pcds/pds/"$HUTCH"/logfiles ami_client
exit
else
- read -p "Do you want to start a second client on the DAQ host $DAQHOST? (y/n)"
+ read -r -p "Do you want to start a second client on the DAQ host $DAQHOST? (y/n)"
if [ "$REPLY" == "n" ];then
exit
else
- echo "Starting another ami_client on "$DAQHOST , calling:
+ echo "Starting another ami_client on ""$DAQHOST" , calling:
fi
fi
else
- echo --- connect to proxy on: $proxy_cds, calling:
-fi
+ echo --- connect to proxy on: "$proxy_cds", calling:
+fi
-echo $ami_path$amicmd
-exec $ami_path$amicmd&
+echo "$ami_path""$amicmd"
+exec "$ami_path""$amicmd"&
diff --git a/scripts/stopami b/scripts/stopami
index 8a25d193..c169e594 100755
--- a/scripts/stopami
+++ b/scripts/stopami
@@ -13,37 +13,41 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then
exit 0
fi
-HUTCH=`get_hutch_name`
-DAQHOST=`wheredaq`
-RESCNT=`echo $DAQHOST |wc| awk {'print $2'}`
-if [ $RESCNT -eq 1 ]; then
- if [ $HOSTNAME == $DAQHOST ]; then
+HUTCH=$(get_hutch_name)
+if [ "$(daqutils isdaqmgr)" = "true" ]; then
+ daqutils --cnf "${HUTCH}"_ami.py stopdaq "$@"
+ exit 0
+fi
+DAQHOST=$(wheredaq)
+RESCNT=$(echo "$DAQHOST" |wc| awk '{print $2}')
+if [ "$RESCNT" -eq 1 ]; then
+ if [ "$HOSTNAME" == "$DAQHOST" ]; then
#running on the DAQ host, this will restart the ami_client!
- read -p "Do you really intend to stop the ami_client on $DAQHOST where the daq is running? (y/n)"
+ read -r -p "Do you really intend to stop the ami_client on $DAQHOST where the daq is running? (y/n)"
if [ "$REPLY" == "y" ];then
echo "Restarting the ami_client...";
- /reg/g/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr stop \
- /reg/g/pcds/dist/pds/$HUTCH/scripts/$HUTCH.cnf ami_client
+ /reg/g/pcds/dist/pds/"$HUTCH"/current/tools/procmgr/procmgr stop \
+ /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$HUTCH".cnf ami_client
fi
fi
fi
-AMI_PROCID=`ps -ef | grep online_ami | grep current | awk {'print $2'}`
-HAVE_ID=`echo $AMI_PROCID | wc | awk {'print $2'}`
-if [ $HAVE_ID -gt 0 ]; then
+AMI_PROCID=$(pgrep online_ami | awk '{print $1}')
+HAVE_ID=$(echo "$AMI_PROCID" | wc | awk '{print $2}')
+if [ "$HAVE_ID" -gt 0 ]; then
for id in $AMI_PROCID; do
- echo 'killing ' $id
- kill $id
+ echo 'killing ' "$id"
+ kill "$id"
done
fi
sleep 2
-AMI_PROCID=`ps -ef | grep online_ami | grep current | awk {'print $2'}`
-HAVE_ID=`echo $AMI_PROCID | wc | awk {'print $2'}`
-if [ $HAVE_ID -gt 0 ]; then
+AMI_PROCID=$(pgrep online_ami | awk '{print $1}')
+HAVE_ID=$(echo "$AMI_PROCID" | wc | awk '{print $2}')
+if [ "$HAVE_ID" -gt 0 ]; then
for id in $AMI_PROCID; do
- echo 'kill -9 ' $id
- kill -9 $id
+ echo 'kill -9 ' "$id"
+ kill -9 "$id"
done
fi