-
Notifications
You must be signed in to change notification settings - Fork 26
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
vespos
wants to merge
5
commits into
pcdshub:master
Choose a base branch
from
vespos:ami2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7c31df8
ami2 script for lcls-1 hutches
vespos ea55093
PR suggestion: inform user of valid hutches
vespos 32b0f15
PR suggestion: inform user of valid hutches
vespos 08b6018
WIP: after dmypy fix + use random graph name to avoid conflict with o…
vespos f4ae758
clean up after releasing the dmypy fix on ami2
vespos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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