<NME> runsh-agent.txt
<BEF> #!/usr/bin/env bash

#
# Generated by Genie for job: JOB_ID_PLACEHOLDER
#

# Error out if any command fails
set -o errexit
# Error out if any command in a pipeline fails
set -o pipefail
# Error out if unknown variable is used
set -o nounset
# Save original stdout and stderr in fd 6 and 7
exec 6>&1
exec 7>&2


# Trap exit signals to ensure children processes are dead before returning
function handle_kill_request {
    echo "Handling $1 signal" >&2
    # Update trap
    trap wait SIGTERM SIGINT SIGHUP
    # Send SIGTERM to all children
    pkill -P $$ || true
    for ((iteration=1; iteration < 30; iteration++))
    {
        if pkill -0 -P $$ &> /dev/null;
        then
            echo "Waiting for children to terminate" >&2
            sleep 1
        else
            echo "All children terminated" >&2
            exit 1
        fi
    }
    # Reaching this point means the children did not die. Kill with SIGKILL
    echo "Terminating all children with SIGKILL" >&2
    pkill -9 -P $$
}
trap 'handle_kill_request SIGTERM' SIGTERM
trap 'handle_kill_request SIGINT' SIGINT
trap 'handle_kill_request SIGHUP' SIGHUP

# Locally-generated environment variables

export GENIE_JOB_DIR="TEST_GENIE_JOB_WORKING_DIR_PLACEHOLDER"

export GENIE_APPLICATION_DIR="${GENIE_JOB_DIR}/genie/applications"

export GENIE_COMMAND_DIR="${GENIE_JOB_DIR}/genie/command/cmd1"

export GENIE_CLUSTER_DIR="${GENIE_JOB_DIR}/genie/cluster/cluster1"

export __GENIE_SETUP_LOG_FILE="${GENIE_JOB_DIR}/genie/logs/setup.log"

export __GENIE_ENVIRONMENT_DUMP_FILE="${GENIE_JOB_DIR}/genie/logs/env.log"

export __GENIE_SETUP_ERROR_MARKER_FILE="${GENIE_JOB_DIR}/genie/setup_failed.txt"


# Mark the beginnig of the setup by creating a marker file
echo "The job script failed during setup. See ${__GENIE_SETUP_LOG_FILE} for details" > ${__GENIE_SETUP_ERROR_MARKER_FILE}

# During setup, redirect stdout and stderr of this script to a log file
exec > ${__GENIE_SETUP_LOG_FILE}
exec 2>&1

echo "Setup start: $(date '+%Y-%m-%d %H:%M:%S')"

# Server-provided environment variables

export GENIE_CLUSTER_ID="cluster1"

export GENIE_CLUSTER_NAME="Local laptop"

export GENIE_CLUSTER_TAGS="localhost"

export GENIE_COMMAND_ID="cmd1"

export GENIE_COMMAND_NAME="Unix Bash command"

export GENIE_COMMAND_TAGS="bash"

export GENIE_JOB_GROUPING="Workflow.Foo"

export GENIE_JOB_GROUPING_INSTANCE="Workflow.Foo_Step.Blah-2020021919:12:34.000_1"

export GENIE_JOB_ID="JOB_ID_PLACEHOLDER"

export GENIE_JOB_MEMORY="1500"

export GENIE_JOB_NAME="List * ... Directories bash job"

export GENIE_JOB_TAGS="aTag,zTag"

export GENIE_REQUESTED_CLUSTER_TAGS="[[localhost]]"

export GENIE_REQUESTED_CLUSTER_TAGS_0="localhost"

export GENIE_REQUESTED_COMMAND_TAGS="bash"

export GENIE_USER="genie"

export GENIE_USER_GROUP=""

export GENIE_VERSION="4"


echo "Sourcing setup script for cluster cluster1"
source ${GENIE_JOB_DIR}/genie/cluster/cluster1/genie_setup.sh

echo "Sourcing setup script for application app1"
source ${GENIE_JOB_DIR}/genie/applications/app1/genie_setup.sh

echo "Sourcing setup script for application app2"
source ${GENIE_JOB_DIR}/genie/applications/app2/genie_setup.sh

echo "Sourcing setup script for command cmd1"
source ${GENIE_JOB_DIR}/genie/command/cmd1/genie_setup.sh

echo "Sourcing setup script for job JOB_ID_PLACEHOLDER"
source ${GENIE_JOB_DIR}/genie_setup.sh


echo "Setup end: $(date '+%Y-%m-%d %H:%M:%S')"

# Setup completed successfully, delete marker file
rm ${__GENIE_SETUP_ERROR_MARKER_FILE}

# Restore the original stdout and stderr. Close fd 6 and 7
exec 1>&6 6>&-
exec 2>&7 7>&-

# Dump environment post-setup
env | sort > ${__GENIE_ENVIRONMENT_DUMP_FILE}

# Launch the command
/bin/bash -c 'sleep 5 && echo hello world' <&0 &
wait %1
exit $?


<MSG> Configurable filtering of job environment debug dump

Add properties to control filtering of the environment variables that are dumped into env.log right before the job starts.
The filter allows configurations such as:
 * Dump nothing
 * Dump everything
 * Dump everything matching <regex>
 * Dump everything except for what matches <regex>

The default values dumps everything (Genie's historical default behavior).

Because this is an agent runtime, the server can override the values globally or per-job.

<DFF> @@ -132,7 +132,7 @@ exec 1>&6 6>&-
 exec 2>&7 7>&-
 
 # Dump environment post-setup
-env | sort > ${__GENIE_ENVIRONMENT_DUMP_FILE}
+env | grep -E --regex='.*' | sort > ${__GENIE_ENVIRONMENT_DUMP_FILE}
 
 # Launch the command
 /bin/bash -c 'sleep 5 && echo hello world' <&0 &

Configurable filtering of job environment debug dump