Skip to content

Commit 624f652

Browse files
committed
Remove dependency on bash from crash/oome uploder scripts
1 parent 2a848ef commit 624f652

File tree

2 files changed

+65
-40
lines changed

2 files changed

+65
-40
lines changed
Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,64 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

3-
set +e # Disable exit on error
3+
# Disable exit on error
4+
set +e
45

56
# Check if PID is provided
67
if [ -z "$1" ]; then
78
echo "Error: No PID provided"
89
exit 1
910
fi
10-
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # Get the directory of the script
11+
12+
# Get the directory of the script
13+
HERE=$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)
1114
PID=$1
1215

13-
# Get the base name of the script
14-
scriptName=$(basename "$0" .sh)
16+
# Get the base name of the script (without .sh)
17+
scriptName=$(basename "$0")
18+
scriptName=${scriptName%.sh}
19+
1520
configFile="${HERE}/${scriptName}_pid${PID}.cfg"
1621
if [ ! -f "$configFile" ]; then
1722
echo "Error: Configuration file not found: $configFile"
1823
exit 1
1924
fi
2025

26+
# Initialize config values
27+
config_agent=""
28+
config_tags=""
29+
config_java_home=""
30+
2131
# Read the configuration file
22-
# The expected contents are:
23-
# - agent: Path to the agent jar
24-
# - tags: Comma-separated list of tags to be sent with the OOME event; key:value pairs are supported
2532
while IFS="=" read -r key value; do
26-
declare "config_$key"="$value"
33+
case "$key" in
34+
agent) config_agent=$value ;;
35+
tags) config_tags=$value ;;
36+
java_home) config_java_home=$value ;;
37+
esac
2738
done < "$configFile"
2839

2940
# Exiting early if configuration is missing
30-
if [ -z "${config_agent}" ] || [ -z "${config_tags}" ] || [ -z "${config_java_home}" ]; then
41+
if [ -z "$config_agent" ] || [ -z "$config_tags" ] || [ -z "$config_java_home" ]; then
3142
echo "Error: Missing configuration"
3243
exit 1
3344
fi
3445

3546
# Debug: Print the loaded values (Optional)
36-
echo "Agent Jar: ${config_agent}"
37-
echo "Tags: ${config_tags}"
38-
echo "JAVA_HOME: ${config_java_home}"
47+
echo "Agent Jar: $config_agent"
48+
echo "Tags: $config_tags"
49+
echo "JAVA_HOME: $config_java_home"
3950
echo "PID: $PID"
4051

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

46-
if [ $RC -eq 0 ]; then
56+
# Remove the configuration file
57+
rm -f "$configFile"
58+
59+
if [ "$RC" -eq 0 ]; then
4760
echo "OOME Event generated successfully"
4861
else
4962
echo "Error: Failed to generate OOME event"
50-
exit $RC
63+
exit "$RC"
5164
fi
Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

3-
set +e # Disable exit on error
3+
# Disable exit on error
4+
set +e
45

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

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

22-
# Get the base name of the script
23-
scriptName=$(basename "$0" .sh)
24+
# Get the base name of the script (without .sh)
25+
scriptName=$(basename "$0")
26+
scriptName=${scriptName%.sh}
27+
2428
configFile="${HERE}/${scriptName}_pid${PID}.cfg"
2529
if [ ! -f "$configFile" ]; then
26-
echo "Error: Configuration file not found: $configFile"
27-
exit 1
30+
echo "Error: Configuration file not found: $configFile"
31+
exit 1
2832
fi
2933

34+
# Initialize config values
35+
config_agent=""
36+
config_hs_err=""
37+
config_java_home=""
38+
3039
# Read the configuration file
31-
# The expected contents are:
32-
# - agent: Path to the agent jar
33-
# - hs_err: Path to the hs_err log file
3440
while IFS="=" read -r key value; do
35-
declare "config_$key"="$value"
41+
case "$key" in
42+
agent) config_agent=$value ;;
43+
hs_err) config_hs_err=$value ;;
44+
java_home) config_java_home=$value ;;
45+
esac
3646
done < "$configFile"
3747

3848
# Exiting early if configuration is missing
39-
if [ -z "${config_agent}" ] || [ -z "${config_hs_err}" ] || [ -z "${config_java_home}" ]; then
40-
echo "Error: Missing configuration"
41-
exit 1
49+
if [ -z "$config_agent" ] || [ -z "$config_hs_err" ] || [ -z "$config_java_home" ]; then
50+
echo "Error: Missing configuration"
51+
exit 1
4252
fi
4353

4454
# Debug: Print the loaded values (Optional)
45-
echo "Agent Jar: ${config_agent}"
46-
echo "Error Log: ${config_hs_err}"
47-
echo "JAVA_HOME: ${config_java_home}"
55+
echo "Agent Jar: $config_agent"
56+
echo "Error Log: $config_hs_err"
57+
echo "JAVA_HOME: $config_java_home"
4858
echo "PID: $PID"
4959

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

55-
if [ $RC -eq 0 ]; then
56-
echo "Error file ${config_hs_err} was uploaded successfully"
64+
# Remove the configuration file
65+
rm -f "$configFile"
66+
67+
if [ "$RC" -eq 0 ]; then
68+
echo "Error file $config_hs_err was uploaded successfully"
5769
else
58-
echo "Error: Failed to upload error file ${config_hs_err}"
59-
exit $RC
70+
echo "Error: Failed to upload error file $config_hs_err"
71+
exit "$RC"
6072
fi

0 commit comments

Comments
 (0)