Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Add option to specify CNF for LCLS2 hutches. Restart/stop AMI only for LCLS2 Hutches. #216

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ usage: restartdaq options<br/>
OPTIONS:<br/>
-w sort windows after start<br/>
-p select partition (same as used last)<br/>
-s silent (do not email jana)
-s silent (do not email jana)<br/>
-C [cnf] : <b>(FOR LCLS2 Hutches)</b> Specify a CNF to run. E.g. qrix.py or crix.py
</td>
</tr>

Expand Down Expand Up @@ -792,6 +793,7 @@ Sourcing this script lets ssh-agent set the proper environment variables it need
usage: startami options<br/>
<br/>
we are starting another ami session here<br/>
<b>This script restarts AMI1 in LCLS1 hutches and AMI2 in LCLS2 hutches</b><br/>
<br/>
OPTIONS:<br/>
-s: stop the ami client current running on this machine<br/>
Expand All @@ -802,7 +804,8 @@ usage: startami options<br/>
<tr>
<td>stopami</td>
<td>
Kill an AMI process running in the current hutch.
Kill an AMI process running in the current hutch.<br/>
<b>This script stops AMI1 in LCLS1 hutches and AMI2 in LCLS2 hutches</b>
</td>
</tr>

Expand Down
7 changes: 5 additions & 2 deletions scripts/daq_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
56 changes: 38 additions & 18 deletions scripts/restartdaq
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -55,6 +49,9 @@ do
c)
CORESIZE=2000000000
;;
C)
DAQMGR_CNF=$OPTARG
;;
d)
DSSTEST=1
;;
Expand All @@ -66,14 +63,37 @@ 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
fi

HUTCH=$(get_info --gethutch)
CNFEXT=.cnf
CNFFILE=$HUTCH$CNFEXT
CNFFILE="$HUTCH""$CNFEXT"
if [ "$HOSTNAME" == 'cxi-daq' ]; then
PEXT=_0
CNFFILE=$HUTCH$PEXT$CNFEXT
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))"
Expand Down
4 changes: 2 additions & 2 deletions scripts/run_daq_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
62 changes: 33 additions & 29 deletions scripts/startami
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then
exit 0
fi

STOP_AMI=0
while getopts "sc:" OPTION
do
case "$OPTION" in
Expand All @@ -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
Expand All @@ -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"&
40 changes: 22 additions & 18 deletions scripts/stopami
Original file line number Diff line number Diff line change
Expand Up @@ -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