From 21d2ac8e9dfb8b3fd387c4f448ffdd020aa1105a Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 9 Apr 2024 00:27:45 +0200 Subject: [PATCH 01/10] Update launchdev.sh to use tmux instead of screen which is deprecated on rocky9 --- scripts/github/prepare-integration.sh | 14 +- tools/launchdev.sh | 309 ++++++++++++++------------ 2 files changed, 172 insertions(+), 151 deletions(-) diff --git a/scripts/github/prepare-integration.sh b/scripts/github/prepare-integration.sh index 9e13ade526..a9011bc080 100755 --- a/scripts/github/prepare-integration.sh +++ b/scripts/github/prepare-integration.sh @@ -30,23 +30,23 @@ echo "" python ./st2client/setup.py develop st2 --version -# Clean up old screen log files -rm -f logs/screen-*.log +# Clean up old st2 log files +rm -f logs/st2*.log # ::group::/::endgroup:: is helpful github actions syntax to fold this section. echo ::group::launchdev.sh start -x -# start dev environment in screens +# start dev environment in tmux ./tools/launchdev.sh start -x # Give processes some time to start and check logs to see if all the services # started or if there was any error / failure -echo "Giving screen processes some time to start..." +echo "Giving st2 processes some time to start..." sleep 10 -echo " === START: Catting screen process log files. ===" -cat logs/screen-*.log -echo " === END: Catting screen process log files. ===" +echo " === START: Catting st2 process log files. ===" +cat logs/st2-*.log +echo " === END: Catting st2 process log files. ===" # github actions: fold for launchdev.sh start -x echo ::endgroup:: diff --git a/tools/launchdev.sh b/tools/launchdev.sh index d0c777f996..2cb352f1a8 100755 --- a/tools/launchdev.sh +++ b/tools/launchdev.sh @@ -1,7 +1,18 @@ #!/usr/bin/env bash +set +x + function usage() { - echo "Usage: $0 [start|stop|restart|startclean] [-r runner_count] [-s scheduler_count] [-w workflow_engine_count] [-g] [-x] [-c] [-6] [-m]" >&2 + cat<&2 + Usage: $0 [start|stop|restart|startclean] [-r runner_count] [-s scheduler_count] [-w workflow_engine_count] [-g] [-x] [-c] [-6] + -r : the number of st2runner instances start + -s : the numer of st2scheduler instances to start + -w : the numer of st2workflow-engine instances to start + -g : disable gunicorn + -x : enable copy test packs + -c : disable load content + -6 : enable use of ipv6 +EOF } subcommand=$1; shift @@ -49,13 +60,49 @@ while getopts ":r:s:w:gxcu6" o; do esac done -function init(){ +# Colour echo +function cecho() +{ + if [[ "$1" == "-n" ]]; then + # No carrage return + NCR="$1"; shift + else + NCR="" + fi + C="$1"; shift + MSG="$1" + echo $NCR -e "\e[${C}m${MSG}\e[0m" +} + +function heading() +{ + MSG="$1" + cecho "34;7" "$MSG" +} +function iecho() +{ + MSG="$1" + cecho "37;1" "$MSG" +} +function wecho() +{ + MSG="$1" + cecho "33;1" "$MSG" +} +function eecho() +{ + MSG="$1" + cecho "31;1" "$MSG" +} +function init() +{ + heading "Initialising system variables ..." ST2_BASE_DIR="/opt/stackstorm" COMMAND_PATH=${0%/*} - CURRENT_DIR=`pwd` - CURRENT_USER=`whoami` - CURRENT_USER_GROUP=`id -gn` - echo "Current user:group = ${CURRENT_USER}:${CURRENT_USER_GROUP}" + CURRENT_DIR=$(pwd) + CURRENT_USER=$(whoami) + CURRENT_USER_GROUP=$(id -gn) + echo -n "Current user:group = "; iecho "${CURRENT_USER}:${CURRENT_USER_GROUP}" if [[ (${COMMAND_PATH} == /*) ]] ; then @@ -63,70 +110,71 @@ function init(){ else ST2_REPO=${CURRENT_DIR}/${COMMAND_PATH}/.. fi - + ST2_LOGS="${ST2_REPO}/logs" VIRTUALENV=${VIRTUALENV_DIR:-${ST2_REPO}/virtualenv} VIRTUALENV=$(readlink -f ${VIRTUALENV}) PY=${VIRTUALENV}/bin/python PYTHON_VERSION=$(${PY} --version 2>&1) - echo "Using virtualenv: ${VIRTUALENV}" - echo "Using python: ${PY} (${PYTHON_VERSION})" + echo -n "Using virtualenv: "; iecho "${VIRTUALENV}" + echo -n "Using python: "; iecho "${PY} (${PYTHON_VERSION})" + echo -n "Log file location: "; iecho "${ST2_LOGS}" if [ -z "$ST2_CONF" ]; then ST2_CONF=${ST2_REPO}/conf/st2.dev.conf fi ST2_CONF=$(readlink -f ${ST2_CONF}) - echo "Using st2 config file: $ST2_CONF" + echo -n "Using st2 config file: "; iecho "$ST2_CONF" if [ ! -f "$ST2_CONF" ]; then - echo "Config file $ST2_CONF does not exist." + eecho "Config file $ST2_CONF does not exist." exit 1 fi } -function exportsdir(){ +function exportsdir() +{ local EXPORTS_DIR=$(grep 'dump_dir' ${ST2_CONF} | sed -e "s~^dump_dir[ ]*=[ ]*\(.*\)~\1~g") if [ -z $EXPORTS_DIR ]; then EXPORTS_DIR="/opt/stackstorm/exports" fi - echo "$EXPORTS_DIR" + echo -n "Export directories: "; iecho "$EXPORTS_DIR" } -function st2start(){ - echo "Starting all st2 servers..." +function st2start() +{ + heading "Starting all st2 servers ..." # Determine where the st2 repo is located. Some assumption is made here # that this script is located under st2/tools. # Change working directory to the root of the repo. - echo "Changing working directory to ${ST2_REPO}" + echo -n "Changing working directory to "; iecho "${ST2_REPO}" cd ${ST2_REPO} - BASE_DIR=$(grep 'base_path' ${ST2_CONF} \ - | awk 'BEGIN {FS=" = "}; {print $2}') + BASE_DIR=$(grep 'base_path' ${ST2_CONF} | awk 'BEGIN {FS=" = "}; {print $2}') if [ -z BASE_DIR ]; then BASE_DIR="/opt/stackstorm" fi CONFIG_BASE_DIR="${BASE_DIR}/configs" - echo "Using config base dir: $CONFIG_BASE_DIR" + echo -n "Using config base dir: "; iecho "$CONFIG_BASE_DIR" if [ ! -d "$CONFIG_BASE_DIR" ]; then - echo "$CONFIG_BASE_DIR doesn't exist. Creating..." + wecho "$CONFIG_BASE_DIR doesn't exist. Creating..." sudo mkdir -p $CONFIG_BASE_DIR fi - PACKS_BASE_DIR=$(grep 'packs_base_path' ${ST2_CONF} \ - | awk 'BEGIN {FS=" = "}; {print $2}') + PACKS_BASE_DIR=$(grep 'packs_base_path' ${ST2_CONF} | awk 'BEGIN {FS=" = "}; {print $2}') if [ -z $PACKS_BASE_DIR ]; then PACKS_BASE_DIR="/opt/stackstorm/packs" fi - echo "Using content packs base dir: $PACKS_BASE_DIR" + echo -n "Using content packs base dir: "; iecho "$PACKS_BASE_DIR" # Copy and overwrite the action contents if [ ! -d "$ST2_BASE_DIR" ]; then - echo "$ST2_BASE_DIR doesn't exist. Creating..." + wecho "$ST2_BASE_DIR doesn't exist. Creating..." sudo mkdir -p $PACKS_BASE_DIR fi @@ -150,7 +198,7 @@ function st2start(){ cp -Rp ./contrib/packs/ $PACKS_BASE_DIR if [ "$copy_test_packs" = true ]; then - echo "Copying test packs examples and fixtures to $PACKS_BASE_DIR" + echo -n "Copying test packs examples and fixtures to "; iecho "$PACKS_BASE_DIR" cp -Rp ./contrib/examples $PACKS_BASE_DIR # Clone st2tests in /tmp directory. pushd /tmp @@ -162,138 +210,112 @@ function st2start(){ cp -Rp ./st2tests/packs/fixtures $PACKS_BASE_DIR rm -R st2tests/ else - echo "Failed to clone st2tests repo" + eecho "Failed to clone st2tests repo" fi popd fi # activate virtualenv to set PYTHONPATH source ${VIRTUALENV}/bin/activate + # set configuration file location. + export ST2_CONFIG_PATH=${ST2_CONF}; - # Kill existing st2 screens - screen -wipe - screen -ls | grep st2 &> /dev/null - if [ $? == 0 ]; then - echo 'Killing existing st2 screen sessions...' - screen -ls | grep st2 | cut -d. -f1 | awk '{print $1}' | xargs kill - fi - - # NOTE: We can't rely on latest version of screen with "-Logfile path" - # option so we need to use screen config file per screen window + # Kill existing st2 terminal multiplexor sessions + for tmux_session in $(tmux ls | awk -F: '/^st2-/ {print $1}') + do + echo "Kill existing session $tmux_session" + tmux kill-session -t $tmux_session + done # Run the st2 API server - echo 'Starting screen session st2-api...' if [ "${use_gunicorn}" = true ]; then - echo ' using gunicorn to run st2-api...' - export ST2_CONFIG_PATH=${ST2_CONF} - screen -L -c tools/screen-configs/st2api.conf -d -m -S st2-api ${VIRTUALENV}/bin/gunicorn \ - st2api.wsgi:application -k eventlet -b "$BINDING_ADDRESS:9101" --workers 1 + echo 'Starting st2-api using gunicorn ...' + # Log standard out, start in daemon mode, load config st2api.conf, session name "st2-api" + tmux new-session -d -s st2-api "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/gunicorn st2api.wsgi:application -k eventlet -b $BINDING_ADDRESS:9100 --workers 1 2>&1 | tee -a ${ST2_LOGS}/st2-api.log" else - screen -L -c tools/screen-configs/st2api.conf -d -m -S st2-api ${VIRTUALENV}/bin/python \ - ./st2api/bin/st2api \ - --config-file $ST2_CONF + echo 'Starting st2-api ...' + tmux new-session -d -s st2-api "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2api/bin/st2api --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-api.log" fi # Run st2stream API server if [ "${use_gunicorn}" = true ]; then - echo ' using gunicorn to run st2-stream' - export ST2_CONFIG_PATH=${ST2_CONF} - screen -L -c tools/screen-configs/st2stream.conf -d -m -S st2-stream ${VIRTUALENV}/bin/gunicorn \ - st2stream.wsgi:application -k eventlet -b "$BINDING_ADDRESS:9102" --workers 1 + echo 'Starting st2-stream using gunicorn ...' + + tmux new-session -d -s st2-stream "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/gunicorn st2stream.wsgi:application -k eventlet -b $BINDING_ADDRESS:9102 --workers 1 2>&1 | tee -a ${ST2_LOGS}/st2-stream.log" else - screen -L -c tools/screen-configs/st2stream.conf -d -m -S st2-stream ${VIRTUALENV}/bin/python \ - ./st2stream/bin/st2stream \ - --config-file $ST2_CONF + echo 'Starting st2-stream ...' + tmux new-session -d -s st2-stream "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2stream/bin/st2stream --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-stream.log" fi # Run the workflow engine server - echo 'Starting screen session st2-workflow(s)' - WORKFLOW_ENGINE_SCREENS=() + echo 'Starting st2-workflow engine(s)' + WORKFLOW_ENGINE_SESSIONS=() for i in $(seq 1 $workflow_engine_count) do WORKFLOW_ENGINE_NAME=st2-workflow-$i - WORKFLOW_ENGINE_SCREENS+=($WORKFLOW_ENGINE_NAME) - echo ' starting '$WORKFLOW_ENGINE_NAME'...' - screen -L -c tools/screen-configs/st2workflowengine.conf -d -m -S $WORKFLOW_ENGINE_NAME ${VIRTUALENV}/bin/python \ - ./st2actions/bin/st2workflowengine \ - --config-file $ST2_CONF + WORKFLOW_ENGINE_SESSIONS+=($WORKFLOW_ENGINE_NAME) + echo " $WORKFLOW_ENGINE_NAME ..." + tmux new-session -d -s $WORKFLOW_ENGINE_NAME "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2actions/bin/st2workflowengine --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/${WORKFLOW_ENGINE_NAME}.log" done # Start a screen for every runner - echo 'Starting screen sessions for st2-actionrunner(s)' - RUNNER_SCREENS=() + echo 'Starting st2-actionrunner(s)' + RUNNER_SESSIONS=() for i in $(seq 1 $runner_count) do RUNNER_NAME=st2-actionrunner-$i - RUNNER_SCREENS+=($RUNNER_NAME) - echo ' starting '$RUNNER_NAME'...' - screen -L -c tools/screen-configs/st2actionrunner.conf -d -m -S $RUNNER_NAME ${VIRTUALENV}/bin/python \ - ./st2actions/bin/st2actionrunner \ - --config-file $ST2_CONF + RUNNER_SESSIONS+=($RUNNER_NAME) + echo " $RUNNER_NAME ..." + tmux new-session -d -s $RUNNER_NAME "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2actions/bin/st2actionrunner --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/${RUNNER_NAME}.log" done # Run the garbage collector service - echo 'Starting screen session st2-garbagecollector' - screen -L -c tools/screen-configs/st2garbagecollector.conf -d -m -S st2-garbagecollector ${VIRTUALENV}/bin/python \ - ./st2reactor/bin/st2garbagecollector \ - --config-file $ST2_CONF + echo 'Starting st2-garbagecollector' + tmux new-session -d -s st2-garbagecollector "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2reactor/bin/st2garbagecollector --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-garbagecollector.log" # Run the scheduler server - echo 'Starting screen session st2-scheduler(s)' - SCHEDULER_SCREENS=() + echo 'Starting st2-scheduler(s)' + SCHEDULER_SESSIONS=() for i in $(seq 1 $scheduler_count) do SCHEDULER_NAME=st2-scheduler-$i - SCHEDULER_SCREENS+=($SCHEDULER_NAME) - echo ' starting '$SCHEDULER_NAME'...' - screen -L -c tools/screen-configs/st2scheduler.conf -d -m -S $SCHEDULER_NAME ${VIRTUALENV}/bin/python \ - ./st2actions/bin/st2scheduler \ - --config-file $ST2_CONF + SCHEDULER_SESSIONS+=($SCHEDULER_NAME) + echo " $SCHEDULER_NAME ..." + tmux new-session -d -s $SCHEDULER_NAME "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2actions/bin/st2scheduler --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/${SCHEDULER_NAME}.log" done # Run the sensor container server - echo 'Starting screen session st2-sensorcontainer' - screen -L -c tools/screen-configs/st2sensorcontainer.conf -d -m -S st2-sensorcontainer ${VIRTUALENV}/bin/python \ - ./st2reactor/bin/st2sensorcontainer \ - --config-file $ST2_CONF + echo 'Starting st2-sensorcontainer' + tmux new-session -d -s st2-sensorcontainer "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2reactor/bin/st2sensorcontainer --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-sensorcontainer.log" # Run the rules engine server - echo 'Starting screen session st2-rulesengine...' - screen -L -c tools/screen-configs/st2rulesengine.conf -d -m -S st2-rulesengine ${VIRTUALENV}/bin/python \ - ./st2reactor/bin/st2rulesengine \ - --config-file $ST2_CONF + echo 'Starting st2-rulesengine...' + tmux new-session -d -s st2-rulesengine "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2reactor/bin/st2rulesengine --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-rulesengine.log" # Run the timer engine server - echo 'Starting screen session st2-timersengine...' - screen -L -c tools/screen-configs/st2timersengine.conf -d -m -S st2-timersengine ${VIRTUALENV}/bin/python \ - ./st2reactor/bin/st2timersengine \ - --config-file $ST2_CONF + echo 'Starting st2-timersengine...' + tmux new-session -d -s st2-timersengine "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2reactor/bin/st2timersengine --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-timersengine.log" # Run the actions notifier - echo 'Starting screen session st2-notifier...' - screen -L -c tools/screen-configs/st2notifier.conf -d -m -S st2-notifier ${VIRTUALENV}/bin/python \ - ./st2actions/bin/st2notifier \ - --config-file $ST2_CONF + echo 'Starting st2-notifier...' + tmux new-session -d -s st2-notifier "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2actions/bin/st2notifier --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-notifier.log" # Run the auth API server - echo 'Starting screen session st2-auth...' if [ "${use_gunicorn}" = true ]; then - echo ' using gunicorn to run st2-auth...' + echo 'Starting st2-auth using gunicorn ...' export ST2_CONFIG_PATH=${ST2_CONF} - screen -L -c tools/screen-configs/st2auth.conf -d -m -S st2-auth ${VIRTUALENV}/bin/gunicorn \ - st2auth.wsgi:application -k eventlet -b "$BINDING_ADDRESS:9100" --workers 1 + tmux new-session -d -s st2-auth "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/gunicorn st2auth.wsgi:application -k eventlet -b $BINDING_ADDRESS:9100 --workers 1 2>&1 | tee -a ${ST2_LOGS}/st2-auth.log" else - screen -L -c tools/screen-configs/st2auth.conf -d -m -S st2-auth ${VIRTUALENV}/bin/python \ - ./st2auth/bin/st2auth \ - --config-file $ST2_CONF + echo 'Starting st2-auth ...' + tmux new-session -d -s st2-auth "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2auth/bin/st2auth --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-auth.log" fi - # Check whether screen sessions are started - SCREENS=( + # Check whether tmux sessions are started + SESSIONS=( "st2-api" - "${WORKFLOW_ENGINE_SCREENS[@]}" - "${SCHEDULER_SCREENS[@]}" - "${RUNNER_SCREENS[@]}" + "${WORKFLOW_ENGINE_SESSIONS[@]}" + "${SCHEDULER_SESSIONS[@]}" + "${RUNNER_SESSIONS[@]}" "st2-sensorcontainer" "st2-rulesengine" "st2-notifier" @@ -303,45 +325,44 @@ function st2start(){ ) echo - for s in "${SCREENS[@]}" + for s in "${SESSIONS[@]}" do - screen -ls | grep "${s}[[:space:]]" &> /dev/null + tmux ls | grep "^${s}[[:space:]]" &> /dev/null if [ $? != 0 ]; then - echo "ERROR: Unable to start screen session for $s." + echo "ERROR: terminal multiplex session for $s failed to start." fi done if [ "$load_content" = true ]; then # Register contents echo 'Registering sensors, runners, actions, rules, aliases, and policies...' - ${VIRTUALENV}/bin/python \ - ./st2common/bin/st2-register-content \ - --config-file $ST2_CONF --register-all + ${VIRTUALENV}/bin/python ./st2common/bin/st2-register-content --config-file $ST2_CONF --register-all fi if [ "$copy_test_packs" = true ]; then st2 run packs.setup_virtualenv packs=fixtures if [ $? != 0 ]; then - echo "Warning: Unable to setup virtualenv for the \"tests\" pack. Please setup virtualenv for the \"tests\" pack before running integration tests" + echo "wecho: Unable to setup virtualenv for the \"tests\" pack. Please setup virtualenv for the \"tests\" pack before running integration tests" fi fi - # Print default creds to the screen - echo "The default creds are testu:testp" + # Display default credentials to the multiplexor session + echo "The default credentials are testu:testp" # List screen sessions - screen -ls || exit 0 + tmux ls || exit 0 } -function st2stop(){ - screen -ls | grep st2 &> /dev/null - if [ $? == 0 ]; then - echo 'Killing existing st2 screen sessions...' - screen -ls | grep st2 | cut -d. -f1 | awk '{print $1}' | xargs -L 1 pkill -P - fi +function st2stop() +{ + for tmux_session in $(tmux ls | awk -F: '/^st2-/ {print $1}') + do + echo "Kill existing session $tmux_session" + tmux kill-session -t $tmux_session + done if [ "${use_gunicorn}" = true ]; then - pids=`ps -ef | grep "wsgi:application" | grep -v "grep" | awk '{print $2}'` + pids=$(ps -ef | grep "wsgi:application" | grep -v "grep" | awk '{print $2}') if [ -n "$pids" ]; then echo "Killing gunicorn processes" # true ensures that any failure to kill a process which does not exist will not lead @@ -354,7 +375,8 @@ function st2stop(){ fi } -function st2clean(){ +function st2clean() +{ # clean mongo . ${VIRTUALENV}/bin/activate python ${ST2_REPO}/st2common/bin/st2-cleanup-db --config-file $ST2_CONF @@ -370,30 +392,29 @@ function st2clean(){ echo "Removing $EXPORTS_DIR..." rm -rf ${EXPORTS_DIR} fi - } case ${subcommand} in -start) - init - st2start - ;; -startclean) - init - st2clean - st2start - ;; -stop) - st2stop - ;; -restart) - st2stop - sleep 1 - init - st2start - ;; -*) - usage - ;; + start) + init + st2start + ;; + startclean) + init + st2clean + st2start + ;; + stop) + st2stop + ;; + restart) + st2stop + sleep 1 + init + st2start + ;; + *) + usage + ;; esac From 100d03859b13cd1b1a7e842de37ef768eee596a6 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Thu, 18 Apr 2024 23:46:54 -0500 Subject: [PATCH 02/10] revert st2api port change in tools/launchdev.sh --- tools/launchdev.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/launchdev.sh b/tools/launchdev.sh index 2cb352f1a8..b2af61053e 100755 --- a/tools/launchdev.sh +++ b/tools/launchdev.sh @@ -231,7 +231,7 @@ function st2start() if [ "${use_gunicorn}" = true ]; then echo 'Starting st2-api using gunicorn ...' # Log standard out, start in daemon mode, load config st2api.conf, session name "st2-api" - tmux new-session -d -s st2-api "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/gunicorn st2api.wsgi:application -k eventlet -b $BINDING_ADDRESS:9100 --workers 1 2>&1 | tee -a ${ST2_LOGS}/st2-api.log" + tmux new-session -d -s st2-api "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/gunicorn st2api.wsgi:application -k eventlet -b $BINDING_ADDRESS:9101 --workers 1 2>&1 | tee -a ${ST2_LOGS}/st2-api.log" else echo 'Starting st2-api ...' tmux new-session -d -s st2-api "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2api/bin/st2api --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-api.log" From 944b67e703ec14a11c5a9e4ae304e579bb0a8743 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Thu, 18 Apr 2024 23:54:04 -0500 Subject: [PATCH 03/10] use ellipses (...) more consistently --- tools/launchdev.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/launchdev.sh b/tools/launchdev.sh index b2af61053e..dc9ee61208 100755 --- a/tools/launchdev.sh +++ b/tools/launchdev.sh @@ -162,7 +162,7 @@ function st2start() echo -n "Using config base dir: "; iecho "$CONFIG_BASE_DIR" if [ ! -d "$CONFIG_BASE_DIR" ]; then - wecho "$CONFIG_BASE_DIR doesn't exist. Creating..." + wecho "$CONFIG_BASE_DIR doesn't exist. Creating ..." sudo mkdir -p $CONFIG_BASE_DIR fi @@ -174,12 +174,12 @@ function st2start() # Copy and overwrite the action contents if [ ! -d "$ST2_BASE_DIR" ]; then - wecho "$ST2_BASE_DIR doesn't exist. Creating..." + wecho "$ST2_BASE_DIR doesn't exist. Creating ..." sudo mkdir -p $PACKS_BASE_DIR fi if [ "${use_ipv6}" = true ]; then - echo ' using IPv6 bindings...' + echo ' using IPv6 bindings ...' BINDING_ADDRESS="[::]" else BINDING_ADDRESS="0.0.0.0" @@ -270,7 +270,7 @@ function st2start() done # Run the garbage collector service - echo 'Starting st2-garbagecollector' + echo 'Starting st2-garbagecollector ...' tmux new-session -d -s st2-garbagecollector "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2reactor/bin/st2garbagecollector --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-garbagecollector.log" # Run the scheduler server @@ -285,19 +285,19 @@ function st2start() done # Run the sensor container server - echo 'Starting st2-sensorcontainer' + echo 'Starting st2-sensorcontainer ...' tmux new-session -d -s st2-sensorcontainer "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2reactor/bin/st2sensorcontainer --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-sensorcontainer.log" # Run the rules engine server - echo 'Starting st2-rulesengine...' + echo 'Starting st2-rulesengine ...' tmux new-session -d -s st2-rulesengine "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2reactor/bin/st2rulesengine --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-rulesengine.log" # Run the timer engine server - echo 'Starting st2-timersengine...' + echo 'Starting st2-timersengine ...' tmux new-session -d -s st2-timersengine "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2reactor/bin/st2timersengine --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-timersengine.log" # Run the actions notifier - echo 'Starting st2-notifier...' + echo 'Starting st2-notifier ...' tmux new-session -d -s st2-notifier "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2actions/bin/st2notifier --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-notifier.log" # Run the auth API server @@ -335,7 +335,7 @@ function st2start() if [ "$load_content" = true ]; then # Register contents - echo 'Registering sensors, runners, actions, rules, aliases, and policies...' + echo 'Registering sensors, runners, actions, rules, aliases, and policies ...' ${VIRTUALENV}/bin/python ./st2common/bin/st2-register-content --config-file $ST2_CONF --register-all fi @@ -389,7 +389,7 @@ function st2clean() fi if [ -n "$ST2_EXPORTER" ]; then EXPORTS_DIR=$(exportsdir) - echo "Removing $EXPORTS_DIR..." + echo "Removing $EXPORTS_DIR ..." rm -rf ${EXPORTS_DIR} fi } From 845add629095cf8f1cf8ecf229ed43a7ecd0ff8a Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 19 Apr 2024 00:36:43 -0500 Subject: [PATCH 04/10] pause in launchdev.sh for database init --- tools/launchdev.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/launchdev.sh b/tools/launchdev.sh index dc9ee61208..cf3425c4cc 100755 --- a/tools/launchdev.sh +++ b/tools/launchdev.sh @@ -230,7 +230,6 @@ function st2start() # Run the st2 API server if [ "${use_gunicorn}" = true ]; then echo 'Starting st2-api using gunicorn ...' - # Log standard out, start in daemon mode, load config st2api.conf, session name "st2-api" tmux new-session -d -s st2-api "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/gunicorn st2api.wsgi:application -k eventlet -b $BINDING_ADDRESS:9101 --workers 1 2>&1 | tee -a ${ST2_LOGS}/st2-api.log" else echo 'Starting st2-api ...' @@ -240,13 +239,15 @@ function st2start() # Run st2stream API server if [ "${use_gunicorn}" = true ]; then echo 'Starting st2-stream using gunicorn ...' - tmux new-session -d -s st2-stream "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/gunicorn st2stream.wsgi:application -k eventlet -b $BINDING_ADDRESS:9102 --workers 1 2>&1 | tee -a ${ST2_LOGS}/st2-stream.log" else echo 'Starting st2-stream ...' tmux new-session -d -s st2-stream "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2stream/bin/st2stream --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-stream.log" fi + # give st2stream time to startup and load things into database + sleep 10 + # Run the workflow engine server echo 'Starting st2-workflow engine(s)' WORKFLOW_ENGINE_SESSIONS=() From 9780d118f8408a7d04ba30ee52ea8c60c6451977 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 19 Apr 2024 00:38:01 -0500 Subject: [PATCH 05/10] improve launchdev messaging --- tools/launchdev.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/launchdev.sh b/tools/launchdev.sh index cf3425c4cc..e38420030a 100755 --- a/tools/launchdev.sh +++ b/tools/launchdev.sh @@ -249,7 +249,7 @@ function st2start() sleep 10 # Run the workflow engine server - echo 'Starting st2-workflow engine(s)' + echo 'Starting st2-workflow engine(s):' WORKFLOW_ENGINE_SESSIONS=() for i in $(seq 1 $workflow_engine_count) do @@ -260,7 +260,7 @@ function st2start() done # Start a screen for every runner - echo 'Starting st2-actionrunner(s)' + echo 'Starting st2-actionrunner(s):' RUNNER_SESSIONS=() for i in $(seq 1 $runner_count) do @@ -275,7 +275,7 @@ function st2start() tmux new-session -d -s st2-garbagecollector "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2reactor/bin/st2garbagecollector --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/st2-garbagecollector.log" # Run the scheduler server - echo 'Starting st2-scheduler(s)' + echo 'Starting st2-scheduler(s):' SCHEDULER_SESSIONS=() for i in $(seq 1 $scheduler_count) do @@ -330,7 +330,7 @@ function st2start() do tmux ls | grep "^${s}[[:space:]]" &> /dev/null if [ $? != 0 ]; then - echo "ERROR: terminal multiplex session for $s failed to start." + eecho "ERROR: terminal multiplex session for $s failed to start." fi done @@ -343,7 +343,7 @@ function st2start() if [ "$copy_test_packs" = true ]; then st2 run packs.setup_virtualenv packs=fixtures if [ $? != 0 ]; then - echo "wecho: Unable to setup virtualenv for the \"tests\" pack. Please setup virtualenv for the \"tests\" pack before running integration tests" + wecho "WARNING: Unable to setup virtualenv for the \"tests\" pack. Please setup virtualenv for the \"tests\" pack before running integration tests" fi fi From 1e1add53d0cf7f97be97238d9a2e9d9e7eb41370 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 19 Apr 2024 01:05:36 -0500 Subject: [PATCH 06/10] remove screen references --- dev_docs/Troubleshooting_Guide.rst | 14 ++++++-------- tools/launchdev.sh | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/dev_docs/Troubleshooting_Guide.rst b/dev_docs/Troubleshooting_Guide.rst index f61cedcba4..1b89ca8a71 100644 --- a/dev_docs/Troubleshooting_Guide.rst +++ b/dev_docs/Troubleshooting_Guide.rst @@ -40,17 +40,15 @@ As we can see from above output port ``9101`` is not even up. To verify this let vagrant 32403 0.2 1.5 79228 31364 pts/3 Ss+ 18:27 0:00 /home/vagrant/git/st2/virtualenv/bin/python ./virtualenv/bin/gunicorn st2stream.wsgi:application -k eventlet -b 0.0.0.0:9102 --workers 1 -- This suggests that the API process crashed, we can verify that by running ``screen -ls``.:: +- This suggests that the API process crashed, we can verify that by running ``tmux ls``.:: .. code:: bash - $ screen -ls - There are screens on: - 15781.st2-auth (04/26/2016 06:39:10 PM) (Detached) - 15778.st2-notifier (04/26/2016 06:39:10 PM) (Detached) - 15767.st2-sensorcontainer (04/26/2016 06:39:10 PM) (Detached) - 15762.st2-stream (04/26/2016 06:39:10 PM) (Detached) - 3 Sockets in /var/run/screen/S-vagrant. + $ tmux ls + st2-auth: 1 windows (created Fri Apr 19 00:42:58 2024) + st2-notifier: 1 windows (created Fri Apr 19 00:42:58 2024) + st2-sensorcontainer: 1 windows (created Fri Apr 19 00:42:58 2024) + st2-stream: 1 windows (created Fri Apr 19 00:42:58 2024) - Now let us check the logs for any errors: diff --git a/tools/launchdev.sh b/tools/launchdev.sh index e38420030a..82d0083f09 100755 --- a/tools/launchdev.sh +++ b/tools/launchdev.sh @@ -259,7 +259,7 @@ function st2start() tmux new-session -d -s $WORKFLOW_ENGINE_NAME "export ST2_CONFIG_PATH=${ST2_CONF}; source ${VIRTUALENV}/bin/activate; ${VIRTUALENV}/bin/python ./st2actions/bin/st2workflowengine --config-file $ST2_CONF 2>&1 | tee -a ${ST2_LOGS}/${WORKFLOW_ENGINE_NAME}.log" done - # Start a screen for every runner + # Start a session for every runner echo 'Starting st2-actionrunner(s):' RUNNER_SESSIONS=() for i in $(seq 1 $runner_count) @@ -350,7 +350,7 @@ function st2start() # Display default credentials to the multiplexor session echo "The default credentials are testu:testp" - # List screen sessions + # List sessions tmux ls || exit 0 } From e53ac69147f2011139e6fe4025e67f29f774d8cc Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 19 Apr 2024 01:07:13 -0500 Subject: [PATCH 07/10] remove unused screen config files --- tools/screen-configs/st2actionrunner.conf | 6 ------ tools/screen-configs/st2api.conf | 6 ------ tools/screen-configs/st2auth.conf | 6 ------ tools/screen-configs/st2garbagecollector.conf | 6 ------ tools/screen-configs/st2notifier.conf | 6 ------ tools/screen-configs/st2rulesengine.conf | 6 ------ tools/screen-configs/st2scheduler.conf | 6 ------ tools/screen-configs/st2sensorcontainer.conf | 6 ------ tools/screen-configs/st2stream.conf | 6 ------ tools/screen-configs/st2timersengine.conf | 6 ------ tools/screen-configs/st2workflowengine.conf | 6 ------ 11 files changed, 66 deletions(-) delete mode 100644 tools/screen-configs/st2actionrunner.conf delete mode 100644 tools/screen-configs/st2api.conf delete mode 100644 tools/screen-configs/st2auth.conf delete mode 100644 tools/screen-configs/st2garbagecollector.conf delete mode 100644 tools/screen-configs/st2notifier.conf delete mode 100644 tools/screen-configs/st2rulesengine.conf delete mode 100644 tools/screen-configs/st2scheduler.conf delete mode 100644 tools/screen-configs/st2sensorcontainer.conf delete mode 100644 tools/screen-configs/st2stream.conf delete mode 100644 tools/screen-configs/st2timersengine.conf delete mode 100644 tools/screen-configs/st2workflowengine.conf diff --git a/tools/screen-configs/st2actionrunner.conf b/tools/screen-configs/st2actionrunner.conf deleted file mode 100644 index c7c8d900a1..0000000000 --- a/tools/screen-configs/st2actionrunner.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2actionrunner.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on diff --git a/tools/screen-configs/st2api.conf b/tools/screen-configs/st2api.conf deleted file mode 100644 index 834313114b..0000000000 --- a/tools/screen-configs/st2api.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2api.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on diff --git a/tools/screen-configs/st2auth.conf b/tools/screen-configs/st2auth.conf deleted file mode 100644 index 0bff41afcb..0000000000 --- a/tools/screen-configs/st2auth.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2auth.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on diff --git a/tools/screen-configs/st2garbagecollector.conf b/tools/screen-configs/st2garbagecollector.conf deleted file mode 100644 index dddb0f68f4..0000000000 --- a/tools/screen-configs/st2garbagecollector.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2garbagecollector.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on diff --git a/tools/screen-configs/st2notifier.conf b/tools/screen-configs/st2notifier.conf deleted file mode 100644 index 104d873a39..0000000000 --- a/tools/screen-configs/st2notifier.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2notifier.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on diff --git a/tools/screen-configs/st2rulesengine.conf b/tools/screen-configs/st2rulesengine.conf deleted file mode 100644 index 1fca4d9807..0000000000 --- a/tools/screen-configs/st2rulesengine.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2rulesengine.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on diff --git a/tools/screen-configs/st2scheduler.conf b/tools/screen-configs/st2scheduler.conf deleted file mode 100644 index 1bbcbd81f6..0000000000 --- a/tools/screen-configs/st2scheduler.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2scheduler.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on diff --git a/tools/screen-configs/st2sensorcontainer.conf b/tools/screen-configs/st2sensorcontainer.conf deleted file mode 100644 index 735550d07b..0000000000 --- a/tools/screen-configs/st2sensorcontainer.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2sensorcontainer.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on diff --git a/tools/screen-configs/st2stream.conf b/tools/screen-configs/st2stream.conf deleted file mode 100644 index e6c6b8c09e..0000000000 --- a/tools/screen-configs/st2stream.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2stream.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on diff --git a/tools/screen-configs/st2timersengine.conf b/tools/screen-configs/st2timersengine.conf deleted file mode 100644 index 5d358d8fec..0000000000 --- a/tools/screen-configs/st2timersengine.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2timersengine.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on diff --git a/tools/screen-configs/st2workflowengine.conf b/tools/screen-configs/st2workflowengine.conf deleted file mode 100644 index 28d110e29c..0000000000 --- a/tools/screen-configs/st2workflowengine.conf +++ /dev/null @@ -1,6 +0,0 @@ -logfile logs/screen-st2workflowengine.log -logfile flush 1 -log on -logtstamp after 1 -logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\" -logtstamp on From 8f92e24732819020134b4c37244ce6186d9f0c41 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Mon, 19 Feb 2024 11:42:41 -0600 Subject: [PATCH 08/10] make gha log capture more useful --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c4c3563be2..5154888a36 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -279,7 +279,7 @@ jobs: if: ${{ failure() }} uses: actions/upload-artifact@v2 with: - name: logs + name: logs-py${{ matrix.python-version }} path: logs.tar.gz retention-days: 7 - name: Stop Redis Service Container @@ -687,7 +687,7 @@ jobs: if: ${{ failure() && env.TASK == 'ci-integration' }} uses: actions/upload-artifact@v2 with: - name: logs + name: logs-py${{ matrix.python-version }}-nose-${{ matrix.nosetests_node_index }} path: logs.tar.gz retention-days: 7 - name: Stop Redis Service Container From 222a0037b5e61a71b9a6ef9dc11bbd45b3cdb2b6 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Wed, 3 Apr 2024 19:27:11 -0500 Subject: [PATCH 09/10] gha: make sure we do not lose collected logs from integration and st2-self-check tests --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5154888a36..703d1eaaa4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -274,6 +274,7 @@ jobs: - name: Compress Service Logs Before upload if: ${{ failure() }} run: | + ./tools/launchdev.sh stop # stop st2 before collecting logs tar cvzpf logs.tar.gz logs/* - name: Upload StackStorm services Logs if: ${{ failure() }} @@ -682,6 +683,7 @@ jobs: - name: Compress Service Logs Before upload if: ${{ failure() && env.TASK == 'ci-integration' }} run: | + ./tools/launchdev.sh stop # stop st2 before collecting logs tar cvzpf logs.tar.gz logs/* - name: Upload StackStorm services Logs if: ${{ failure() && env.TASK == 'ci-integration' }} From 634e83e787157490cc2eda27db3056fb4ab5a39e Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 19 Apr 2024 01:40:53 -0500 Subject: [PATCH 10/10] add changelog entry --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fd3b485148..10da613b59 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,7 @@ Changed ~~~~~~~ * Bumped `jsonschema` 2.6.0 -> 3.2.0 now that python3.6 is not supported. #6118 * Bumped many deps based on the lockfile generated by pants+pex. #6181 (by @cognifloyd and @nzlosh) +* Refactor `tools/launchdev.sh` to use `tmux` instead of `screen`. #6186 (by @nzlosh and @cognifloyd) Added ~~~~~