Keep camera streaming active across MQTT updates

This commit is contained in:
Andrei Smaliak 2026-10-08 18:27:14 +02:00
parent fb70bfcbd1
commit b06248fa9f
11 changed files with 45 additions and 17 deletions

View File

@ -0,0 +1,6 @@
# Edge Console 3.1.22
- Report a stopped IP Camera Streaming service explicitly when its local control socket is unavailable instead of exposing the operating-system `No such file or directory` error.
- Keep the Console and IP Camera Streaming diagnostics aligned so operators can distinguish an installed FFmpeg binary from an inactive streaming service.
Validation: audited `g-box-c453df5f` through its authenticated Console and Cockpit tunnel. Console 3.1.21 and streaming 1.0.7 were current, FFmpeg was installed, but the streaming service had exited successfully during the MQTT stage update and was not restarted. The service was restored and its control socket and gateway FFmpeg spawn path were verified.

View File

@ -0,0 +1,9 @@
# IP Camera Streaming 1.0.8
Release date: 2026-10-08.
- Keep IP Camera Streaming running across MQTT stage updates. Mosquitto is now a soft startup dependency, so the MQTT installer's separate stop/start cycle cannot leave streaming stopped; the persistent service restarts after any subscriber exit and reconnects when the broker returns.
- Require executable FFmpeg and FFprobe binaries before systemd starts the service, and use their canonical system paths at runtime.
- Report a stopped streaming service explicitly when its local control socket is unavailable instead of exposing the operating-system `No such file or directory` error.
Validation: reproduced on `g-box-c453df5f`. The MQTT 1.0.2 update restarted Mosquitto, the streaming subscriber exited successfully, and `Restart=on-failure` left the service inactive. After a controlled restart, the service, control socket and gateway FFmpeg spawn check are healthy. Unit and Console regression tests cover the corrected lifecycle and error mapping.

View File

@ -14,7 +14,7 @@
"version": "1.0.1" "version": "1.0.1"
}, },
"stage_ui": { "stage_ui": {
"version": "3.1.21" "version": "3.1.22"
}, },
"stage_avahi": { "stage_avahi": {
"version": "1.0.0" "version": "1.0.0"
@ -31,7 +31,7 @@
}, },
"optional_stages": { "optional_stages": {
"stage_ip_stream": { "stage_ip_stream": {
"version": "1.0.7" "version": "1.0.8"
} }
} }
} }

View File

@ -1,13 +1,14 @@
[Unit] [Unit]
Description=IOMATEX IP camera streaming service Description=IOMATEX IP camera streaming service
After=network-online.target mosquitto.service After=network-online.target mosquitto.service
Wants=network-online.target Wants=network-online.target mosquitto.service
Requires=mosquitto.service
[Service] [Service]
Type=simple Type=simple
ExecStartPre=/usr/bin/test -x /usr/bin/ffmpeg
ExecStartPre=/usr/bin/test -x /usr/bin/ffprobe
ExecStart=/usr/local/lib/iomatex/ip-stream.py ExecStart=/usr/local/lib/iomatex/ip-stream.py
Restart=on-failure Restart=always
RestartSec=5 RestartSec=5
User=iomatex-stream User=iomatex-stream
Group=iomatex-stream Group=iomatex-stream

View File

@ -22,6 +22,8 @@ SUPPORTED_INPUT_SCHEMES = {"rtsp"}
SUPPORTED_OUTPUT_SCHEMES = {"rtsp", "rtmp", "srt", "udp"} SUPPORTED_OUTPUT_SCHEMES = {"rtsp", "rtmp", "srt", "udp"}
MAX_STREAMS = 8 MAX_STREAMS = 8
PREVIEW_TTL_SEC = 10 * 60 PREVIEW_TTL_SEC = 10 * 60
FFMPEG_BINARY = "/usr/bin/ffmpeg"
FFPROBE_BINARY = "/usr/bin/ffprobe"
def edge_id(): def edge_id():
@ -168,7 +170,7 @@ class StreamManager:
if len(self.processes) >= MAX_STREAMS: if len(self.processes) >= MAX_STREAMS:
raise RuntimeError("stream limit reached") raise RuntimeError("stream limit reached")
command = [ command = [
"ffmpeg", "-nostdin", "-hide_banner", "-loglevel", "warning", FFMPEG_BINARY, "-nostdin", "-hide_banner", "-loglevel", "warning",
"-rtsp_transport", "tcp", "-i", input_url, "-rtsp_transport", "tcp", "-i", input_url,
"-map", "0:v:0", "-map", "0:a?", *video_arguments(payload), "-map", "0:v:0", "-map", "0:a?", *video_arguments(payload),
"-c:a", "libopus", "-b:a", "64k", "-ar", "48000", "-ac", "1", "-c:a", "libopus", "-b:a", "64k", "-ar", "48000", "-ac", "1",
@ -222,7 +224,7 @@ class StreamManager:
manifest_path = preview_dir / "index.m3u8" manifest_path = preview_dir / "index.m3u8"
segment_pattern = preview_dir / "segment-%06d.m4s" segment_pattern = preview_dir / "segment-%06d.m4s"
command = [ command = [
"ffmpeg", "-nostdin", "-hide_banner", "-loglevel", "warning", FFMPEG_BINARY, "-nostdin", "-hide_banner", "-loglevel", "warning",
"-rtsp_transport", "tcp", "-i", input_url, "-rtsp_transport", "tcp", "-i", input_url,
"-map", "0:v:0", "-map", "0:a?", "-c:v", "copy", "-map", "0:v:0", "-map", "0:a?", "-c:v", "copy",
"-c:a", "aac", "-b:a", "64k", "-ar", "48000", "-ac", "1", "-c:a", "aac", "-b:a", "64k", "-ar", "48000", "-ac", "1",
@ -253,7 +255,7 @@ class StreamManager:
snapshot_path = preview_dir / "snapshot.jpg" snapshot_path = preview_dir / "snapshot.jpg"
temporary_path = preview_dir / "snapshot.tmp.jpg" temporary_path = preview_dir / "snapshot.tmp.jpg"
command = [ command = [
"ffmpeg", "-nostdin", "-hide_banner", "-loglevel", "error", "-y", FFMPEG_BINARY, "-nostdin", "-hide_banner", "-loglevel", "error", "-y",
"-rtsp_transport", "tcp", "-i", input_url, "-rtsp_transport", "tcp", "-i", input_url,
"-map", "0:v:0", "-frames:v", "1", "-q:v", "2", str(temporary_path), "-map", "0:v:0", "-frames:v", "1", "-q:v", "2", str(temporary_path),
] ]
@ -283,7 +285,7 @@ class StreamManager:
def validate(self, payload): def validate(self, payload):
input_url = validate_url(payload.get("input_url"), SUPPORTED_INPUT_SCHEMES) input_url = validate_url(payload.get("input_url"), SUPPORTED_INPUT_SCHEMES)
command = [ command = [
"ffprobe", "-v", "error", "-rtsp_transport", "tcp", FFPROBE_BINARY, "-v", "error", "-rtsp_transport", "tcp",
"-show_streams", "-show_format", "-of", "json", input_url, "-show_streams", "-show_format", "-of", "json", input_url,
] ]
try: try:

View File

@ -15,7 +15,13 @@ SPEC.loader.exec_module(stream)
class IpStreamTest(unittest.TestCase): class IpStreamTest(unittest.TestCase):
def test_installer_restarts_an_existing_service(self): def test_installer_restarts_an_existing_service(self):
installer = MODULE_PATH.with_name("stage_ip_stream_install.sh").read_text(encoding="utf-8") installer = MODULE_PATH.with_name("stage_ip_stream_install.sh").read_text(encoding="utf-8")
service = MODULE_PATH.with_name("iomatex-ip-stream.service").read_text(encoding="utf-8")
self.assertIn("systemctl restart iomatex-ip-stream.service", installer) self.assertIn("systemctl restart iomatex-ip-stream.service", installer)
self.assertIn("ExecStartPre=/usr/bin/test -x /usr/bin/ffmpeg", service)
self.assertIn("ExecStartPre=/usr/bin/test -x /usr/bin/ffprobe", service)
self.assertIn("Wants=network-online.target mosquitto.service", service)
self.assertNotIn("Requires=mosquitto.service", service)
self.assertIn("Restart=always", service)
self.assertIn("ffprobe -version", installer) self.assertIn("ffprobe -version", installer)
self.assertNotIn("enable --now iomatex-ip-stream.service", installer) self.assertNotIn("enable --now iomatex-ip-stream.service", installer)
@ -192,7 +198,7 @@ class IpStreamTest(unittest.TestCase):
self.assertTrue(result["reachable"]) self.assertTrue(result["reachable"])
self.assertEqual(result["video_codec"], "h264") self.assertEqual(result["video_codec"], "h264")
self.assertEqual(result["audio_codec"], "aac") self.assertEqual(result["audio_codec"], "aac")
self.assertIn("ffprobe", command.call_args.args[0]) self.assertIn(stream.FFPROBE_BINARY, command.call_args.args[0])
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,3 +1,3 @@
{ {
"version": "1.0.7" "version": "1.0.8"
} }

View File

@ -56,7 +56,7 @@ APP_DIR = "/opt/iomatex-console"
PUBLIC_DIR = os.path.join(APP_DIR, "public") PUBLIC_DIR = os.path.join(APP_DIR, "public")
PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d") PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d")
CONFIG_PATH = "/etc/iomatex/console.json" CONFIG_PATH = "/etc/iomatex/console.json"
UI_VERSION = "V 3.1.21" UI_VERSION = "V 3.1.22"
STORAGE_HEALTH_COMMAND = "/usr/local/sbin/iomatex-storage-health" STORAGE_HEALTH_COMMAND = "/usr/local/sbin/iomatex-storage-health"
ZONEINFO_ROOT = "/usr/share/zoneinfo" ZONEINFO_ROOT = "/usr/share/zoneinfo"
@ -219,7 +219,10 @@ def publish_camera_preview(payload):
body = json.dumps(payload, separators=(",", ":")).encode("utf-8") body = json.dumps(payload, separators=(",", ":")).encode("utf-8")
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client: with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
client.settimeout(20) client.settimeout(20)
client.connect(IOMATEX_IP_STREAM_SOCKET_PATH) try:
client.connect(IOMATEX_IP_STREAM_SOCKET_PATH)
except (FileNotFoundError, ConnectionRefusedError) as exc:
raise RuntimeError("IP camera streaming service is not running") from exc
client.sendall(body) client.sendall(body)
client.shutdown(socket.SHUT_WR) client.shutdown(socket.SHUT_WR)
response = bytearray() response = bytearray()

View File

@ -16,6 +16,7 @@ class CameraPreviewContractTest(unittest.TestCase):
self.assertIn('"action": "preview_start"', source) self.assertIn('"action": "preview_start"', source)
self.assertIn('"action": "snapshot"', source) self.assertIn('"action": "snapshot"', source)
self.assertIn('IOMATEX_IP_STREAM_SOCKET_PATH', source) self.assertIn('IOMATEX_IP_STREAM_SOCKET_PATH', source)
self.assertIn('IP camera streaming service is not running', source)
self.assertIn('wait_camera_snapshot(stream_id, previous_mtime_ns)', source) self.assertIn('wait_camera_snapshot(stream_id, previous_mtime_ns)', source)
self.assertIn('content_type = "image/jpeg"', source) self.assertIn('content_type = "image/jpeg"', source)
self.assertIn('"Access-Control-Allow-Origin": "*"', source) self.assertIn('"Access-Control-Allow-Origin": "*"', source)

View File

@ -23,7 +23,7 @@
} catch (error) {} } catch (error) {}
})(); })();
</script> </script>
<link rel="stylesheet" href="/console.css?v=3.1.20&amp;rev=camera-snapshot-1"> <link rel="stylesheet" href="/console.css?v=3.1.22&amp;rev=camera-snapshot-1">
</head> </head>
<body> <body>
<main class="shell"> <main class="shell">
@ -109,7 +109,7 @@
</main> </main>
<div id="menuBackdrop" class="menuBackdrop" hidden></div> <div id="menuBackdrop" class="menuBackdrop" hidden></div>
<div id="toastStack" class="toastStack" aria-live="polite" aria-atomic="true"></div> <div id="toastStack" class="toastStack" aria-live="polite" aria-atomic="true"></div>
<script src="/console.i18n.js?v=3.1.20&amp;rev=camera-snapshot-1"></script> <script src="/console.i18n.js?v=3.1.22&amp;rev=camera-snapshot-1"></script>
<script src="/console.js?v=3.1.20&amp;rev=camera-snapshot-1"></script> <script src="/console.js?v=3.1.22&amp;rev=camera-snapshot-1"></script>
</body> </body>
</html> </html>

View File

@ -1,3 +1,3 @@
{ {
"version": "3.1.21" "version": "3.1.22"
} }