From 7c31df882163785d58f93a82d42c1a52c4484410 Mon Sep 17 00:00:00 2001 From: Vincent Esposito Date: Tue, 8 Oct 2024 18:00:17 -0700 Subject: [PATCH 1/8] ami2 script for lcls-1 hutches --- scripts/startami2 | 101 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100755 scripts/startami2 diff --git a/scripts/startami2 b/scripts/startami2 new file mode 100755 index 00000000..6638867e --- /dev/null +++ b/scripts/startami2 @@ -0,0 +1,101 @@ +#!/bin/bash + +# ----------- Functions ----------- +get_status(){ + grep ami2_ $STATUS_FILE | awk {'print $1"\t"$2"\t"$3'} +} +echo + + +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 + 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 + + From ea5509337a40f3880d28e92eae7d448d6d48995f Mon Sep 17 00:00:00 2001 From: Vincent Esposito Date: Wed, 6 Nov 2024 17:32:06 -0800 Subject: [PATCH 2/8] PR suggestion: inform user of valid hutches --- scripts/startami2 | 48 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/scripts/startami2 b/scripts/startami2 index 6638867e..ce78d721 100755 --- a/scripts/startami2 +++ b/scripts/startami2 @@ -2,17 +2,16 @@ # ----------- Functions ----------- get_status(){ - grep ami2_ $STATUS_FILE | awk {'print $1"\t"$2"\t"$3'} + grep "ami2_ $STATUS_FILE" | awk '{print $1"\t"$2"\t"$3}' } -echo 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 + 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) @@ -23,8 +22,8 @@ start_new_client(){ 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 - + ami-client -H "$AMI2_MGR_HOST" + else echo "Manager not in running state. Can't start a client." echo "Manager: $MGR_STATUS" @@ -33,22 +32,24 @@ start_new_client(){ restart_all(){ + # Restart all the AMI2-related proc-servers for i in "${!AMI2_PROC[@]}" do - echo ${AMI2_PROC[i]} - echo ${AMI2_HOST[i]} - echo ${AMI2_STATUS[i]} - $PROCMGR restart $CNF ${AMI2_PROC[i]} + 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 for i in "${!AMI2_PROC[@]}" do - echo ${AMI2_PROC[i]} - echo ${AMI2_HOST[i]} - echo ${AMI2_STATUS[i]} - $PROCMGR stop $CNF ${AMI2_PROC[i]} + echo "${AMI2_PROC[i]}" + echo "${AMI2_HOST[i]}" + echo "${AMI2_STATUS[i]}" + $PROCMGR stop "$CNF" "${AMI2_PROC[i]}" done } @@ -65,10 +66,11 @@ fi if [[ $# -lt 2 ]]; then HUTCH=${HOSTNAME:0:3} HUTCHES=("xpp" "xcs" "mfx" "cxi" "mec") - if [[ ${HUTCHES[@]} =~ $HUTCH ]]; then + 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 @@ -79,12 +81,12 @@ 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 +$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'}`) +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 @@ -96,6 +98,4 @@ elif [[ $CMD == "stop" ]]; then stop_all fi -rm $STATUS_FILE - - +rm "$STATUS_FILE" From 32b0f15b6ba66e32a7f32c75970f2a10fc1c378a Mon Sep 17 00:00:00 2001 From: Vincent Esposito Date: Wed, 6 Nov 2024 17:52:33 -0800 Subject: [PATCH 3/8] PR suggestion: inform user of valid hutches --- scripts/startami2 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/startami2 b/scripts/startami2 index ce78d721..cdeb73c4 100755 --- a/scripts/startami2 +++ b/scripts/startami2 @@ -33,8 +33,8 @@ start_new_client(){ restart_all(){ # Restart all the AMI2-related proc-servers - for i in "${!AMI2_PROC[@]}" - do + echo "Restarting all AMI2 processes" + for i in "${!AMI2_PROC[@]}"; do echo "${AMI2_PROC[i]}" echo "${AMI2_HOST[i]}" echo "${AMI2_STATUS[i]}" @@ -44,6 +44,7 @@ restart_all(){ stop_all(){ # Stops all the AMI2-related proc-servers + echo "Stopping all AMI2 processes" for i in "${!AMI2_PROC[@]}" do echo "${AMI2_PROC[i]}" @@ -84,9 +85,12 @@ 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}') +# 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 From 08b6018049678860c20f8309b61306396f9e19e3 Mon Sep 17 00:00:00 2001 From: Vincent Esposito Date: Thu, 7 Nov 2024 18:12:16 -0800 Subject: [PATCH 4/8] WIP: after dmypy fix + use random graph name to avoid conflict with other client --- scripts/startami2 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/startami2 b/scripts/startami2 index cdeb73c4..95203d49 100755 --- a/scripts/startami2 +++ b/scripts/startami2 @@ -2,26 +2,34 @@ # ----------- Functions ----------- get_status(){ - grep "ami2_ $STATUS_FILE" | awk '{print $1"\t"$2"\t"$3}' + 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 - 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 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 PATH=/cds/group/pcds/epics-dev/espov/packages/ami2/install-lcls1/bin:/cds/group/pcds/epics-dev/espov/packages/ami2/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 MYPYPATH=/cds/group/pcds/epics-dev/espov/packages/ami2/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 PYTHONPATH=/cds/group/pcds/epics-dev/espov/packages/ami2/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 Date: Tue, 12 Nov 2024 16:50:09 -0800 Subject: [PATCH 5/8] clean up after releasing the dmypy fix on ami2 --- scripts/startami2 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/startami2 b/scripts/startami2 index 95203d49..476e3746 100755 --- a/scripts/startami2 +++ b/scripts/startami2 @@ -18,12 +18,9 @@ start_new_client(){ # 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 PATH=/cds/group/pcds/epics-dev/espov/packages/ami2/install-lcls1/bin:/cds/group/pcds/epics-dev/espov/packages/ami2/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 MYPYPATH=/cds/group/pcds/epics-dev/espov/packages/ami2/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 PYTHONPATH=/cds/group/pcds/epics-dev/espov/packages/ami2/install-lcls1/lib/python3.9/site-packages + 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/ From aa3f3dac752eb53865904be08d176f257db7fc44 Mon Sep 17 00:00:00 2001 From: Vincent Esposito Date: Mon, 9 Dec 2024 16:45:03 -0800 Subject: [PATCH 6/8] acutally pass the custom graph name... --- scripts/startami2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/startami2 b/scripts/startami2 index 476e3746..2d108038 100755 --- a/scripts/startami2 +++ b/scripts/startami2 @@ -27,7 +27,7 @@ start_new_client(){ GRAPH_NAME="graph_$(tr -dc A-Za-z0-9 Date: Mon, 9 Dec 2024 16:51:03 -0800 Subject: [PATCH 7/8] readme for startammi2 --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index e046e9c6..8a1dbd12 100644 --- a/README.md +++ b/README.md @@ -799,6 +799,21 @@ usage: startami options
+> + startami2 + +usage: startami2
+
+ AMI2 commands for LCLS-I
+
+ COMMANDS:
+ status: print the status of AMI processes
+ restart: restart all AMI processes
+ stop: stop all AMI processes
+ client: start a second AMI client, connecting to the existing manager + + + stopami From 4eaaf9d9ff1d60473388eb0238658bc0af8ef268 Mon Sep 17 00:00:00 2001 From: Vincent Esposito Date: Tue, 10 Dec 2024 18:48:20 -0800 Subject: [PATCH 8/8] handle cxi and make sure we dont touch monreq processes --- scripts/startami2 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/startami2 b/scripts/startami2 index 2d108038..4d4490ae 100755 --- a/scripts/startami2 +++ b/scripts/startami2 @@ -40,6 +40,9 @@ 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]}" @@ -50,8 +53,10 @@ restart_all(){ stop_all(){ # Stops all the AMI2-related proc-servers echo "Stopping all AMI2 processes" - for i in "${!AMI2_PROC[@]}" - do + 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]}" @@ -84,10 +89,14 @@ else fi PROCMGR="/cds/group/pcds/dist/pds/$HUTCH/current/tools/procmgr/procmgr" -CNF="/reg/g/pcds/dist/pds/$HUTCH/scripts/$HUTCH.cnf" +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 /cds/group/pcds/dist/pds/"$HUTCH"/scripts/"$HUTCH".cnf > "$STATUS_FILE" +$PROCMGR status "$CNF" > "$STATUS_FILE" AMI2_MGR_HOST=$(grep ami2_manager "$STATUS_FILE" | awk '{print $1}') # shellcheck disable=SC2207