From 11e7e994a4639da07876b2777a12e2fcc337db95 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Sat, 9 May 2026 11:24:53 +0200 Subject: [PATCH] Docker: Video recording starts via session capability se:recordVideo Signed-off-by: Viet Nguyen Duc --- NodeBase/Dockerfile | 4 ++-- Video/recorder.conf | 8 ++++---- Video/uploader.conf | 4 ++-- Video/video_nodeQuery.py | 7 +++++-- Video/video_recorder.py | 23 +++++++++++++++++------ 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/NodeBase/Dockerfile b/NodeBase/Dockerfile index 7948e47f2c..2889083727 100644 --- a/NodeBase/Dockerfile +++ b/NodeBase/Dockerfile @@ -61,8 +61,8 @@ ENV LANG_WHICH=${LANG_WHICH} \ #============================ # Some configuration options #============================ - SE_RECORD_VIDEO=false \ - SE_VIDEO_FILE_NAME=auto \ + SE_RECORD_VIDEO="false" \ + SE_VIDEO_FILE_NAME="auto" \ SE_VIDEO_EVENT_DRIVEN="true" \ DISPLAY_CONTAINER_NAME="localhost" \ SE_SCREEN_WIDTH="1920" \ diff --git a/Video/recorder.conf b/Video/recorder.conf index ef0edac83a..d60da93718 100755 --- a/Video/recorder.conf +++ b/Video/recorder.conf @@ -2,9 +2,9 @@ priority=10 command=python3 /opt/bin/video_recorder.py killasgroup=true -autostart=%(ENV_SE_RECORD_VIDEO)s +autostart=true startsecs=0 -autorestart=%(ENV_SE_RECORD_VIDEO)s +autorestart=true stopsignal=TERM stopwaitsecs=30 @@ -17,9 +17,9 @@ stdout_logfile_maxbytes=0 priority=0 command=python3 /opt/bin/video_ready.py killasgroup=true -autostart=%(ENV_SE_RECORD_VIDEO)s +autostart=true startsecs=0 -autorestart=%(ENV_SE_RECORD_VIDEO)s +autorestart=true stopsignal=TERM stopwaitsecs=5 diff --git a/Video/uploader.conf b/Video/uploader.conf index 5fc5ac9f15..f837d1fde2 100644 --- a/Video/uploader.conf +++ b/Video/uploader.conf @@ -2,9 +2,9 @@ priority=5 command=python3 /opt/bin/video_uploader.py killasgroup=true -autostart=%(ENV_SE_VIDEO_UPLOAD_ENABLED)s +autostart=true startsecs=0 -autorestart=%(ENV_SE_VIDEO_UPLOAD_ENABLED)s +autorestart=true stopsignal=TERM stopwaitsecs=30 diff --git a/Video/video_nodeQuery.py b/Video/video_nodeQuery.py index 17e2e782d4..26d0bd32cd 100644 --- a/Video/video_nodeQuery.py +++ b/Video/video_nodeQuery.py @@ -25,6 +25,7 @@ def main() -> None: # Environment variables with defaults video_cap_name = os.environ.get("VIDEO_CAP_NAME", "se:recordVideo") + default_record_video = os.environ.get("SE_RECORD_VIDEO", "true").lower() != "false" test_name_cap = os.environ.get("TEST_NAME_CAP", "se:name") video_name_cap = os.environ.get("VIDEO_NAME_CAP", "se:videoName") video_file_name_trim = os.environ.get("SE_VIDEO_FILE_NAME_TRIM_REGEX", default_trim_pattern) @@ -46,8 +47,10 @@ def main() -> None: # If JSON parsing fails, continue with None values pass - # Check if enabling to record video - if (isinstance(record_video, str) and record_video.lower() == "false") or record_video is False: + # Check if enabling to record video; fall back to SE_RECORD_VIDEO when capability is absent + if record_video is None: + record_video = "true" if default_record_video else "false" + elif (isinstance(record_video, str) and record_video.lower() == "false") or record_video is False: record_video = "false" else: record_video = "true" diff --git a/Video/video_recorder.py b/Video/video_recorder.py index 84fb1f54e3..8c57604067 100755 --- a/Video/video_recorder.py +++ b/Video/video_recorder.py @@ -18,6 +18,7 @@ import signal import subprocess import sys +import time def _signal_supervisord() -> None: @@ -83,22 +84,32 @@ def _mark_external_shutdown(signum, frame): def _run_shell_recorder(): + record_video = os.environ.get("SE_RECORD_VIDEO", "true").lower() == "true" + per_session_mode = os.environ.get("SE_VIDEO_FILE_NAME", "") == "auto" + + if not record_video and not per_session_mode: + print("[video.recorder] - SE_RECORD_VIDEO is disabled and SE_VIDEO_FILE_NAME is not 'auto', idling.") + try: + while True: + time.sleep(60) + except KeyboardInterrupt: + pass + return + proc = subprocess.Popen(["/opt/bin/video.sh"]) _external_shutdown = False # True when supervisord (or user) told us to stop def forward_signal(signum, frame): nonlocal _external_shutdown - # Forward the signal to video.sh at most once. supervisord uses - # killasgroup=true so video.sh already received the signal directly; - # re-forwarding on every re-entrant call amplifies the SIGTERM - # ping-pong and can keep the process alive for 60 s. if not _external_shutdown: _external_shutdown = True try: proc.send_signal(signum) except ProcessLookupError: - pass # Process already exited before signal was forwarded - proc.wait() + pass + # Do NOT call proc.wait() here — blocking inside a signal handler + # interferes with bash's deferred-signal queue. The main-flow + # proc.wait() below resumes automatically after this returns (PEP 475). signal.signal(signal.SIGTERM, forward_signal) signal.signal(signal.SIGINT, forward_signal)