-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·121 lines (90 loc) · 3.37 KB
/
run.sh
File metadata and controls
executable file
·121 lines (90 loc) · 3.37 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
## example: sudo -E script -q -c "./run.sh" output.txt
## cat output.txt | grep "Aggregate counter so far is"
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
export PYTHONVERBOSE=0
# Check if JRTC_PATH is set
if [ -z "$JRTC_PATH" ]; then
echo "Error: JRTC_PATH environment variable is not set. Please set it before running this script."
exit 1
fi
# Array to track background process IDs
PIDS=()
# Function to run a command in the background and track its PID
run_background_command() {
local cmd="$1"
echo "Running in background: $cmd"
eval "$cmd &"
PIDS+=($!) # Store the PID of the background process
}
# Function to clean up all spawned processes
cleanup() {
echo "Cleaning up spawned processes..."
# Kill child processes of this script first
pkill -P $$
# Kill all tracked PIDs explicitly
for pid in "${PIDS[@]}"; do
if ps -p $pid > /dev/null 2>&1; then
echo "Killing process with PID $pid"
kill -9 $pid
fi
done
# Additional cleanup: kill jrtc-related processes by name
echo "Killing any remaining JRTC processes..."
pgrep -f 'run_jrtc.sh' | xargs -r kill -9
pgrep -f 'simple_agent_ipc' | xargs -r kill -9
pgrep -f 'run_reverse_proxy.sh' | xargs -r kill -9
pgrep -f 'run_decoder.sh' | xargs -r kill -9
pgrep -f '/out/bin/jrtc' | xargs -r kill -9
pgrep -f 'proxy --address /tmp/jbpf/jbpf_lcm_ipc' | xargs -r kill -9
pgrep -f 'jrtc-ctl decoder run' | xargs -r kill -9
echo "Cleanup complete."
}
# Set trap to clean up processes on script exit
trap cleanup EXIT
# Trap Ctrl C
trap cleanup SIGINT
# Step 1: Run JRTC
run_background_command "cd $JRTC_PATH/sample_apps/first_example_py && source ../../setup_jrtc_env.sh && ./run_jrtc.sh"
sleep 3
# Step 2: Run Jbpf IPC agent
run_background_command "cd $JRTC_PATH/sample_apps/first_example_py && source ../../setup_jrtc_env.sh && ./run_simple_agent_ipc.sh"
sleep 1
# Step 3: Run reverse proxy
run_background_command "cd $JRTC_PATH/sample_apps/first_example_py && source ../../setup_jrtc_env.sh && ./run_reverse_proxy.sh"
sleep 1
# Step 4: Run decoder
run_background_command "cd $JRTC_PATH/sample_apps/first_example_py && source ../../setup_jrtc_env.sh && ./run_decoder.sh"
sleep 1
# Step 5: Load YAML (runs in the foreground)
echo "Running: Load YAML"
cd $JRTC_PATH/sample_apps/first_example_py && source ../../setup_jrtc_env.sh
## to test if we can load in any directory
cd $JRTC_PATH
sample_apps/first_example_py/load_app.sh
## Wait to see output
echo "Waiting for output..."
sleep 20
# Step 6: Unload YAML (runs in the foreground)
echo "Running: Unload YAML"
cd $JRTC_PATH/sample_apps/first_example_py && source ../../setup_jrtc_env.sh
cd $JRTC_PATH
sample_apps/first_example_py/unload_app.sh
echo "---------------------- Now load and unload to make sure if all works again ----------------------"
sleep 5
### Step 7: Load YAML (runs in the foreground)
echo "Running: Load YAML"
cd $JRTC_PATH/sample_apps/first_example_py && source ../../setup_jrtc_env.sh
cd $JRTC_PATH
sample_apps/first_example_py/load_app.sh
## Wait to see output
echo "Waiting for output..."
sleep 20
# Step 8: Unload YAML (runs in the foreground)
echo "Running: Unload YAML"
cd $JRTC_PATH/sample_apps/first_example_py && source ../../setup_jrtc_env.sh
## Unload again
cd $JRTC_PATH
sample_apps/first_example_py/unload_app.sh
echo "Test completed."