-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathAllClustersTestApp.sh
More file actions
executable file
·60 lines (45 loc) · 1.78 KB
/
AllClustersTestApp.sh
File metadata and controls
executable file
·60 lines (45 loc) · 1.78 KB
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
#!/bin/bash
# Wrapper script for allclustersapp
# Captures stdout/stderr to log file and handles SIGTERM
# Path to the real executable
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REAL_PROGRAM="$SCRIPT_DIR/dist/esm/AllClustersTestApp.js"
# Log file (hardcoded)
LOG_FILE="./test_allclusters.log"
# Variable to store the PID of the wrapped process
CHILD_PID=""
# Function to handle SIGTERM
sigterm_handler() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - Received SIGTERM, forwarding to child process (PID: $CHILD_PID)" | tee -a "$LOG_FILE"
EXIT_CODE=0
if [ -n "$CHILD_PID" ]; then
kill -TERM "$CHILD_PID" 2>/dev/null
wait "$CHILD_PID"
EXIT_CODE=$?
fi
# If the child reported 134 (abort), normalize to 0 for the SIGTERM case
if [ "$EXIT_CODE" -eq 134 ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - Normalizing exit code 134 -> 0 after SIGTERM" | tee -a "$LOG_FILE"
EXIT_CODE=0
fi
# Log completion
echo "$(date '+%Y-%m-%d %H:%M:%S') - allclustersapp exited with code after SIGTERM: $EXIT_CODE" | tee -a "$LOG_FILE"
# Exit with the same code as the wrapped program
exit $EXIT_CODE
}
# Set up SIGTERM trap
trap sigterm_handler SIGTERM
# Log start
echo "$(date '+%Y-%m-%d %H:%M:%S') - Starting allclustersapp with arguments: $@" | tee -a "$LOG_FILE"
# Run the real program with all arguments, capturing stdout and stderr
# Using process substitution to tee both streams
"$REAL_PROGRAM" "$@" > >(tee -a "$LOG_FILE") 2> >(tee -a "$LOG_FILE" >&2) &
# Store the PID
CHILD_PID=$!
# Wait for the process to complete
wait "$CHILD_PID"
EXIT_CODE=$?
# Log completion
echo "$(date '+%Y-%m-%d %H:%M:%S') - allclustersapp exited with code: $EXIT_CODE" | tee -a "$LOG_FILE"
# Exit with the same code as the wrapped program
exit $EXIT_CODE