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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
110 changes: 110 additions & 0 deletions scripts/startami2
Copy link
Member

Choose a reason for hiding this comment

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

I think the main thing missing from my point of view is including this script in the readme table

Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

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


start_new_client(){
# Just start a client to connect to an existing manager
MGR_STATUS=$(grep ami2_manager "$STATUS_FILE" | awk '{print $3}')
rm "$STATUS_FILE"
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:/usr/bin:/usr/local/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/

GRAPH_NAME="graph_$(tr -dc A-Za-z0-9 </dev/urandom | head -c 4;)"
echo "Command: $(which ami-client) -H $AMI2_MGR_HOST -g $GRAPH_NAME"
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(){
# Restart all the AMI2-related proc-servers
echo "Restarting all AMI2 processes"
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(){
# Stops all the AMI2-related proc-servers
echo "Stopping all AMI2 processes"
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"
echo "Valid hutches are '${HUTCHES[*]}'. This is a LCLS-I only tool."
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}')
# shellcheck disable=SC2207
AMI2_PROC=($(grep ami2_ "$STATUS_FILE" | awk '{print $2}'))
# shellcheck disable=SC2207
AMI2_HOST=($(grep ami2_ "$STATUS_FILE" | awk '{print $1}'))
# shellcheck disable=SC2207
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"