Skip to content

Commit 2585eaa

Browse files
authored
Docker: Video recording starts via session capability se:recordVideo (#3131)
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
1 parent 44b85be commit 2585eaa

5 files changed

Lines changed: 30 additions & 16 deletions

File tree

NodeBase/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ ENV LANG_WHICH=${LANG_WHICH} \
6161
#============================
6262
# Some configuration options
6363
#============================
64-
SE_RECORD_VIDEO=false \
65-
SE_VIDEO_FILE_NAME=auto \
64+
SE_RECORD_VIDEO="false" \
65+
SE_VIDEO_FILE_NAME="auto" \
6666
SE_VIDEO_EVENT_DRIVEN="true" \
6767
DISPLAY_CONTAINER_NAME="localhost" \
6868
SE_SCREEN_WIDTH="1920" \

Video/recorder.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
priority=10
33
command=python3 /opt/bin/video_recorder.py
44
killasgroup=true
5-
autostart=%(ENV_SE_RECORD_VIDEO)s
5+
autostart=true
66
startsecs=0
7-
autorestart=%(ENV_SE_RECORD_VIDEO)s
7+
autorestart=true
88
stopsignal=TERM
99
stopwaitsecs=30
1010

@@ -17,9 +17,9 @@ stdout_logfile_maxbytes=0
1717
priority=0
1818
command=python3 /opt/bin/video_ready.py
1919
killasgroup=true
20-
autostart=%(ENV_SE_RECORD_VIDEO)s
20+
autostart=true
2121
startsecs=0
22-
autorestart=%(ENV_SE_RECORD_VIDEO)s
22+
autorestart=true
2323
stopsignal=TERM
2424
stopwaitsecs=5
2525

Video/uploader.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
priority=5
33
command=python3 /opt/bin/video_uploader.py
44
killasgroup=true
5-
autostart=%(ENV_SE_VIDEO_UPLOAD_ENABLED)s
5+
autostart=true
66
startsecs=0
7-
autorestart=%(ENV_SE_VIDEO_UPLOAD_ENABLED)s
7+
autorestart=true
88
stopsignal=TERM
99
stopwaitsecs=30
1010

Video/video_nodeQuery.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def main() -> None:
2525

2626
# Environment variables with defaults
2727
video_cap_name = os.environ.get("VIDEO_CAP_NAME", "se:recordVideo")
28+
default_record_video = os.environ.get("SE_RECORD_VIDEO", "true").lower() != "false"
2829
test_name_cap = os.environ.get("TEST_NAME_CAP", "se:name")
2930
video_name_cap = os.environ.get("VIDEO_NAME_CAP", "se:videoName")
3031
video_file_name_trim = os.environ.get("SE_VIDEO_FILE_NAME_TRIM_REGEX", default_trim_pattern)
@@ -46,8 +47,10 @@ def main() -> None:
4647
# If JSON parsing fails, continue with None values
4748
pass
4849

49-
# Check if enabling to record video
50-
if (isinstance(record_video, str) and record_video.lower() == "false") or record_video is False:
50+
# Check if enabling to record video; fall back to SE_RECORD_VIDEO when capability is absent
51+
if record_video is None:
52+
record_video = "true" if default_record_video else "false"
53+
elif (isinstance(record_video, str) and record_video.lower() == "false") or record_video is False:
5154
record_video = "false"
5255
else:
5356
record_video = "true"

Video/video_recorder.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import signal
1919
import subprocess
2020
import sys
21+
import time
2122

2223

2324
def _signal_supervisord() -> None:
@@ -83,22 +84,32 @@ def _mark_external_shutdown(signum, frame):
8384

8485

8586
def _run_shell_recorder():
87+
record_video = os.environ.get("SE_RECORD_VIDEO", "true").lower() == "true"
88+
per_session_mode = os.environ.get("SE_VIDEO_FILE_NAME", "") == "auto"
89+
90+
if not record_video and not per_session_mode:
91+
print("[video.recorder] - SE_RECORD_VIDEO is disabled and SE_VIDEO_FILE_NAME is not 'auto', idling.")
92+
try:
93+
while True:
94+
time.sleep(60)
95+
except KeyboardInterrupt:
96+
pass
97+
return
98+
8699
proc = subprocess.Popen(["/opt/bin/video.sh"])
87100
_external_shutdown = False # True when supervisord (or user) told us to stop
88101

89102
def forward_signal(signum, frame):
90103
nonlocal _external_shutdown
91-
# Forward the signal to video.sh at most once. supervisord uses
92-
# killasgroup=true so video.sh already received the signal directly;
93-
# re-forwarding on every re-entrant call amplifies the SIGTERM
94-
# ping-pong and can keep the process alive for 60 s.
95104
if not _external_shutdown:
96105
_external_shutdown = True
97106
try:
98107
proc.send_signal(signum)
99108
except ProcessLookupError:
100-
pass # Process already exited before signal was forwarded
101-
proc.wait()
109+
pass
110+
# Do NOT call proc.wait() here — blocking inside a signal handler
111+
# interferes with bash's deferred-signal queue. The main-flow
112+
# proc.wait() below resumes automatically after this returns (PEP 475).
102113

103114
signal.signal(signal.SIGTERM, forward_signal)
104115
signal.signal(signal.SIGINT, forward_signal)

0 commit comments

Comments
 (0)