-
Notifications
You must be signed in to change notification settings - Fork 300
/
Copy pathupload_crash.sh
60 lines (50 loc) · 1.68 KB
/
upload_crash.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
set +e # Disable exit on error
# Check if PID is provided
if [ -z "$1" ]; then
echo "Warn: No PID provided. Running in legacy mode."
"!JAVA_HOME!/bin/java" -jar "!AGENT_JAR!" uploadCrash "!JAVA_ERROR_FILE!"
if [ $? -eq 0 ]; then
echo "Error file !JAVA_ERROR_FILE! was uploaded successfully"
else
echo "Error: Failed to upload error file \"!JAVA_ERROR_FILE!\""
exit 1
fi
exit 0
fi
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # Get the directory of the script
PID=$1
# Get the base name of the script
scriptName=$(basename "$0" .sh)
configFile="${HERE}/${scriptName}_pid${PID}.cfg"
if [ ! -f "$configFile" ]; then
echo "Error: Configuration file not found: $configFile"
exit 1
fi
# 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"
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
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 "PID: $PID"
# Execute the Java command with the loaded values
"${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"
else
echo "Error: Failed to upload error file ${config_hs_err}"
exit $RC
fi