Skip to content

Remove dependency on bash from crash/oome uploder scripts #8652

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

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,51 +1,64 @@
#!/usr/bin/env bash
#!/bin/sh

set +e # Disable exit on error
# Disable exit on error
set +e

# Check if PID is provided
if [ -z "$1" ]; then
echo "Error: No PID provided"
exit 1
fi
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # Get the directory of the script

# Get the directory of the script
HERE=$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)
PID=$1

# Get the base name of the script
scriptName=$(basename "$0" .sh)
# Get the base name of the script (without .sh)
scriptName=$(basename "$0")
scriptName=${scriptName%.sh}

configFile="${HERE}/${scriptName}_pid${PID}.cfg"
if [ ! -f "$configFile" ]; then
echo "Error: Configuration file not found: $configFile"
exit 1
fi

# Initialize config values
config_agent=""
config_tags=""
config_java_home=""

# Read the configuration file
# The expected contents are:
# - agent: Path to the agent jar
# - tags: Comma-separated list of tags to be sent with the OOME event; key:value pairs are supported
while IFS="=" read -r key value; do
declare "config_$key"="$value"
case "$key" in
agent) config_agent=$value ;;
tags) config_tags=$value ;;
java_home) config_java_home=$value ;;
esac
done < "$configFile"

# Exiting early if configuration is missing
if [ -z "${config_agent}" ] || [ -z "${config_tags}" ] || [ -z "${config_java_home}" ]; then
if [ -z "$config_agent" ] || [ -z "$config_tags" ] || [ -z "$config_java_home" ]; then
echo "Error: Missing configuration"
exit 1
fi

# Debug: Print the loaded values (Optional)
echo "Agent Jar: ${config_agent}"
echo "Tags: ${config_tags}"
echo "JAVA_HOME: ${config_java_home}"
echo "Agent Jar: $config_agent"
echo "Tags: $config_tags"
echo "JAVA_HOME: $config_java_home"
echo "PID: $PID"

# Execute the Java command with the loaded values
"${config_java_home}/bin/java" -Ddd.dogstatsd.start-delay=0 -jar "${config_agent}" sendOomeEvent "${config_tags}"
"$config_java_home/bin/java" -Ddd.dogstatsd.start-delay=0 -jar "$config_agent" sendOomeEvent "$config_tags"
RC=$?
rm -f "${configFile}" # Remove the configuration file

if [ $RC -eq 0 ]; then
# Remove the configuration file
rm -f "$configFile"

if [ "$RC" -eq 0 ]; then
echo "OOME Event generated successfully"
else
echo "Error: Failed to generate OOME event"
exit $RC
exit "$RC"
fi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
#!/bin/sh

set +e # Disable exit on error
# Disable exit on error
set +e

# Check if PID is provided
if [ -z "$1" ]; then
Expand All @@ -16,45 +17,56 @@ if [ -z "$1" ]; then
exit 0
fi

HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # Get the directory of the script
# Get the directory of the script
HERE=$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)
PID=$1

# Get the base name of the script
scriptName=$(basename "$0" .sh)
# Get the base name of the script (without .sh)
scriptName=$(basename "$0")
scriptName=${scriptName%.sh}

configFile="${HERE}/${scriptName}_pid${PID}.cfg"
if [ ! -f "$configFile" ]; then
echo "Error: Configuration file not found: $configFile"
exit 1
echo "Error: Configuration file not found: $configFile"
exit 1
fi

# Initialize config values
config_agent=""
config_hs_err=""
config_java_home=""

# Read the configuration file
# The expected contents are:
# - agent: Path to the agent jar
# - hs_err: Path to the hs_err log file
while IFS="=" read -r key value; do
declare "config_$key"="$value"
case "$key" in
agent) config_agent=$value ;;
hs_err) config_hs_err=$value ;;
java_home) config_java_home=$value ;;
esac
done < "$configFile"

# Exiting early if configuration is missing
if [ -z "${config_agent}" ] || [ -z "${config_hs_err}" ] || [ -z "${config_java_home}" ]; then
echo "Error: Missing configuration"
exit 1
if [ -z "$config_agent" ] || [ -z "$config_hs_err" ] || [ -z "$config_java_home" ]; then
echo "Error: Missing configuration"
exit 1
fi

# Debug: Print the loaded values (Optional)
echo "Agent Jar: ${config_agent}"
echo "Error Log: ${config_hs_err}"
echo "JAVA_HOME: ${config_java_home}"
echo "Agent Jar: $config_agent"
echo "Error Log: $config_hs_err"
echo "JAVA_HOME: $config_java_home"
echo "PID: $PID"

# Execute the Java command with the loaded values
"${config_java_home}/bin/java" -jar "${config_agent}" uploadCrash "${config_hs_err}"
"$config_java_home/bin/java" -jar "$config_agent" uploadCrash "$config_hs_err"
RC=$?
rm -f "${configFile}" # Remove the configuration file

if [ $RC -eq 0 ]; then
echo "Error file ${config_hs_err} was uploaded successfully"
# Remove the configuration file
rm -f "$configFile"

if [ "$RC" -eq 0 ]; then
echo "Error file $config_hs_err was uploaded successfully"
else
echo "Error: Failed to upload error file ${config_hs_err}"
exit $RC
echo "Error: Failed to upload error file $config_hs_err"
exit "$RC"
fi