From 0cd8e733ff894342861ff93e45f72a162362fc4d Mon Sep 17 00:00:00 2001 From: Zak Lee Date: Tue, 22 Oct 2024 14:52:52 -0700 Subject: [PATCH] x11vnc: autorestart and logging (#54) --- computer-use-demo/image/x11vnc_startup.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/computer-use-demo/image/x11vnc_startup.sh b/computer-use-demo/image/x11vnc_startup.sh index 3ada566d..1f2909ba 100755 --- a/computer-use-demo/image/x11vnc_startup.sh +++ b/computer-use-demo/image/x11vnc_startup.sh @@ -12,6 +12,8 @@ echo "starting vnc" -rfbport 5900 \ 2>/tmp/x11vnc_stderr.log) & +x11vnc_pid=$! + # Wait for x11vnc to start timeout=10 while [ $timeout -gt 0 ]; do @@ -23,9 +25,25 @@ while [ $timeout -gt 0 ]; do done if [ $timeout -eq 0 ]; then - echo "x11vnc stderr output:" >&2 + echo "x11vnc failed to start, stderr output:" >&2 cat /tmp/x11vnc_stderr.log >&2 exit 1 fi -rm /tmp/x11vnc_stderr.log +: > /tmp/x11vnc_stderr.log + +# Monitor x11vnc process in the background +( + while true; do + if ! kill -0 $x11vnc_pid 2>/dev/null; then + echo "x11vnc process crashed, restarting..." >&2 + if [ -f /tmp/x11vnc_stderr.log ]; then + echo "x11vnc stderr output:" >&2 + cat /tmp/x11vnc_stderr.log >&2 + rm /tmp/x11vnc_stderr.log + fi + exec "$0" + fi + sleep 5 + done +) &