-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from vespos/ami2
ami2 script for lcls-1 hutches
- Loading branch information
Showing
2 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/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" -g "$GRAPH_NAME" | ||
|
||
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 | ||
if [[ ${AMI2_PROC[i]} =~ "monreqsrv" ]]; then | ||
continue # skip monreq processes that might have ami2 in their name | ||
fi | ||
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 | ||
if [[ ${AMI2_PROC[i]} =~ "monreqsrv" ]]; then | ||
continue # skip monreq processes that might have ami2 in their name | ||
fi | ||
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 | ||
fi | ||
else | ||
HUTCH=$2 | ||
fi | ||
|
||
PROCMGR="/cds/group/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr" | ||
if [[ $HUTCH == "cxi" ]]; then | ||
CNF="/reg/g/pcds/dist/pds/$HUTCH/scripts/cxi_0.cnf" # special CXI case... | ||
else | ||
CNF="/reg/g/pcds/dist/pds/$HUTCH/scripts/$HUTCH.cnf" | ||
fi | ||
STATUS_FILE="/tmp/ami2_procmgr_status_$USER" | ||
|
||
$PROCMGR status "$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" |