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

ami2 script for lcls-1 hutches #212

Merged
merged 8 commits into from
Dec 14, 2024
101 changes: 101 additions & 0 deletions scripts/startami2
vespos marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

# ----------- Functions -----------
get_status(){
grep ami2_ $STATUS_FILE | awk {'print $1"\t"$2"\t"$3'}
}
echo
Copy link
Member

@ZLLentz ZLLentz Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this echo left here by accident, or does it do something?



start_new_client(){
# Just start a client to connect to an existing manager
MGR_STATUS=(`grep ami2_manager $STATUS_FILE | awk {'print $3'}`)
if [[ $MGR_STATUS == RUNNING ]]; then
echo "Manager running on $AMI2_MGR_HOST."

echo "Starting AMI2 client on $(hostname)."

# These exports are needed (as they are in the cnf file, see ami2_env)
export PATH=/reg/g/pcds/dist/pds/$HUTCH/ami2-current/install-lcls1/bin:/reg/g/pcds/dist/pds/$HUTCH/ami2-current/install-lcls1/condadir/bin
export MYPYPATH=/reg/g/pcds/dist/pds/$HUTCH/ami2-current/install-lcls1/lib/python3.9/site-packages
export PYTHONPATH=/reg/g/pcds/dist/pds/$HUTCH/ami2-current/install-lcls1/lib/python3.9/site-packages
export SIT_ROOT=/cds/data/psdm
export SIT_PSDM_DATA=/cds/data/psdm
export SIT_DATA=/cds/sw/ds/ana/conda1/inst/envs/ana-4.0.62-py3/data:/cds/group/psdm/data/

ami-client -H $AMI2_MGR_HOST

else
echo "Manager not in running state. Can't start a client."
echo "Manager: $MGR_STATUS"
fi
}


restart_all(){
for i in "${!AMI2_PROC[@]}"
do
echo ${AMI2_PROC[i]}
echo ${AMI2_HOST[i]}
echo ${AMI2_STATUS[i]}
$PROCMGR restart $CNF ${AMI2_PROC[i]}
done
}

stop_all(){
for i in "${!AMI2_PROC[@]}"
do
echo ${AMI2_PROC[i]}
echo ${AMI2_HOST[i]}
echo ${AMI2_STATUS[i]}
$PROCMGR stop $CNF ${AMI2_PROC[i]}
done
}



# ----------- Main -----------
if [[ $# -lt 1 ]]; then
CMD="status"
echo "Default: CMD: $CMD"
else
CMD=$1
fi

if [[ $# -lt 2 ]]; then
HUTCH=${HOSTNAME:0:3}
HUTCHES=("xpp" "xcs" "mfx" "cxi" "mec")
if [[ ${HUTCHES[@]} =~ $HUTCH ]]; then
echo "Valid hutch found: $HUTCH"
else
echo "Invalid hutch: $HUTCH"
exit 1
vespos marked this conversation as resolved.
Show resolved Hide resolved
fi
else
HUTCH=$2
fi

PROCMGR="/cds/group/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr"
CNF="/reg/g/pcds/dist/pds/$HUTCH/scripts/$HUTCH.cnf"
STATUS_FILE="/tmp/ami2_procmgr_status_$USER"

$PROCMGR status /cds/group/pcds/dist/pds/$HUTCH/scripts/$HUTCH.cnf > $STATUS_FILE

AMI2_MGR_HOST=(`grep ami2_manager $STATUS_FILE | awk {'print $1'}`)
AMI2_PROC=(`grep ami2_ $STATUS_FILE | awk {'print $2'}`)
AMI2_HOST=(`grep ami2_ $STATUS_FILE | awk {'print $1'}`)
AMI2_STATUS=(`grep ami2_ $STATUS_FILE | awk {'print $3'}`)

if [[ $CMD == "status" ]]; then
get_status
elif [[ $CMD == "client" ]]; then
start_new_client
elif [[ $CMD == "restart" ]]; then
restart_all
elif [[ $CMD == "stop" ]]; then
stop_all
fi

rm $STATUS_FILE


Loading