diff --git a/entrypoint.sh b/entrypoint.sh index 5a06166..376a182 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,13 +2,41 @@ source /opt/ros/humble/setup.bash # make VNC port configurable (prepare for moving to a dedicated port) -vnc_port="${VNC_PORT:=3000}" +# vnc_port="${VNC_PORT:=3000}" # start X11 server -Xvfb :0 -screen 0 1920x1080x16 & +# Xvfb :0 -screen 0 1920x1080x16 & # start VNC server -x11vnc -display :0 -rfbport "$vnc_port" -forever -xkb -noxrecord -noxfixes -noshm -nopw -wait 5 -shared & +# x11vnc -display :0 -rfbport "$vnc_port" -forever -xkb -noxrecord -noxfixes -noshm -nopw -wait 5 -shared & # start window manager -HOME=/root DISPLAY=:0 USER=root openbox +# HOME=/root DISPLAY=:0 USER=root openbox + +export DISPLAY=${DISPLAY:-:0} +export XAUTHORITY=/tmp/.docker.xauth + +ros-with-env ros2 run rviz2 rviz2 & + +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: Detector sim failed with code $RESULT" >&2 + exit $RESULT +else + echo "INFO: Detector sim finished successfully, but returning 125 code for docker to restart properly." >&2 + exit 125 +fi