forked from allenh1/rplidar_ros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·66 lines (57 loc) · 1.85 KB
/
entrypoint.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
61
62
63
64
65
66
#!/bin/bash -e
_term() {
# FILL UP PROCESS SEARCH PATTERN HERE TO FIND PROPER PROCESS FOR SIGINT:
pattern="fcu_to_garmin_static_transform_publisher"
pid_value="$(ps -a | grep $pattern | grep -v grep | awk '{ print $1 }')"
if [ "$pid_value" != "" ]; then
pid=$pid_value
echo "Send SIGINT to pid $pid"
else
pid=1
echo "Pattern not found, send SIGINT to pid $pid"
fi
kill -s SIGINT $pid
pattern="fcu_to_rplidar_static_transform_publisher"
pid_value="$(ps -a | grep $pattern | grep -v grep | awk '{ print $1 }')"
if [ "$pid_value" != "" ]; then
pid=$pid_value
echo "Send SIGINT to pid $pid"
else
pid=1
echo "Pattern not found, send SIGINT to pid $pid"
fi
kill -s SIGINT $pid
pattern="rplidar_ros2/rplidar"
pid_value="$(ps -a | grep $pattern | grep -v grep | awk '{ print $1 }')"
if [ "$pid_value" != "" ]; then
pid=$pid_value
echo "Send SIGINT to pid $pid"
else
pid=1
echo "Pattern not found, send SIGINT to pid $pid"
fi
kill -s SIGINT $pid
}
# Use SIGTERM or TERM, does not seem to make any difference.
trap _term SIGTERM
ros-with-env ros2 launch rplidar_ros2 sensors_launch.py &
child=$!
echo "Waiting for pid $child"
# * Calling "wait" will then wait for the job with the specified by $child to finish, or for any signals to be fired.
# Due to "or for any signals to be fired", "wait" will also handle SIGTERM and it will shutdown before
# the node ends gracefully.
# The solution is to add a second "wait" call and remove the trap between the two calls.
# * Do not use -e flag in the first wait call because wait will exit with error after catching SIGTERM.
set +e
wait $child
set -e
trap - TERM
wait $child
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "ERROR: RPLidar failed with code $RESULT" >&2
exit $RESULT
else
echo "INFO: RPLidar finished successfully, but returning 125 code for docker to restart properly." >&2
exit 125
fi