-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauto_restart.sh
More file actions
executable file
·82 lines (64 loc) · 1.78 KB
/
auto_restart.sh
File metadata and controls
executable file
·82 lines (64 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# ログにTracebackが出たら関連プロセスを一通りkillして
# 一定時間後に再起動するためのスクリプト
# 実行方法:
# ./auto_restart.sh
LAUNCH_PGID=""
# kill対象プロセス名の一覧
pkill_targets=(
"consai_visualizer"
"component_conta"
"parameter_publisher"
"consai_referee_parser"
"controller.launch.py"
)
cleanup() {
echo "Interrupted! Cleaning up..."
if [ -n "$LAUNCH_PGID" ]; then
echo "Killing process group $LAUNCH_PGID"
kill -- -"$LAUNCH_PGID" 2>/dev/null
fi
echo "Killing residual processes..."
for target in "${pkill_targets[@]}"; do
pkill -9 -f "$target"
done
exit 0
}
trap cleanup SIGINT
if [ -z ${CONSAI_COLOR} ]; then
YELLOW="false"
elif [ ${CONSAI_COLOR} = "yellow" ]; then
YELLOW="true"
elif [ ${CONSAI_COLOR} = "blue" ]; then
YELLOW="false"
fi
if [ -z ${CONSAI_SIDE} ]; then
INVERT="false"
elif [ ${CONSAI_SIDE} = "right" ]; then
INVERT="true"
elif [ ${CONSAI_SIDE} = "left" ]; then
INVERT="false"
fi
while true; do
echo "Starting CONSAI ROS2..."
# launch起動+リアルタイム出力
setsid bash -c "ros2 launch consai_game start.launch yellow:=${YELLOW} invert:=${INVERT} 2>&1 | tee ros2_output.log" &
LAUNCH_PID=$!
echo "ROS2 leader PID: $LAUNCH_PID"
LAUNCH_PGID=$(ps -o pgid= "$LAUNCH_PID" | tr -d ' ')
echo "Captured PGID: $LAUNCH_PGID"
tail -F ros2_output.log | while read line; do
echo "$line" | grep -q "Traceback"
if [ $? -eq 0 ]; then
echo "Detected Traceback, terminating all child processes..."
kill -- -"$LAUNCH_PGID"
echo "Killing residual processes..."
for target in "${pkill_targets[@]}"; do
pkill -9 -f "$target"
done
break
fi
done
echo "Restarting in 5 seconds..."
sleep 5
done