From f29cf43f52a3ab23231a161e7f92400a00784712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Farkas?= <68812986+Netesfiu@users.noreply.github.com> Date: Wed, 9 Jul 2025 17:49:57 +0200 Subject: [PATCH 1/5] Update edgetpu.md (#19067) Updated "USB Coral Not Detected" section with troubleshooting steps for QNAP NAS devices. --- docs/docs/troubleshooting/edgetpu.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/docs/troubleshooting/edgetpu.md b/docs/docs/troubleshooting/edgetpu.md index 8f3cb0db7..3587898c8 100644 --- a/docs/docs/troubleshooting/edgetpu.md +++ b/docs/docs/troubleshooting/edgetpu.md @@ -40,6 +40,17 @@ Some users have reported that this older device runs an older kernel causing iss 6. Open the control panel - info scree. The coral TPU will now be recognised as a USB Device - google inc 7. Start the frigate container. Everything should work now! +### QNAP NAS + +QNAP NAS devices, such as the TS-253A, may use connected Coral TPU devices if [QuMagie](https://www.qnap.com/en/software/qumagie) is installed along with its QNAP AI Core extension. If any of the features—`facial recognition`, `object recognition`, or `similar photo recognition`—are enabled, Container Station applications such as `Frigate` or `CodeProject.AI Server` will be unable to initialize the TPU device in use. +To allow the Coral TPU device to be discovered, the you must either: + +1. [Disable the AI recognition features in QuMagie](https://docs.qnap.com/application/qumagie/2.x/en-us/configuring-qnap-ai-core-settings-FB13CE03.html), +2. Remove the QNAP AI Core extension or +3. Manually start the QNAP AI Core extension after Frigate has fully started (not recommended). + +It is also recommended to restart the NAS once the changes have been made. + ## USB Coral Detection Appears to be Stuck The USB Coral can become stuck and need to be restarted, this can happen for a number of reasons depending on hardware and software setup. Some common reasons are: From 213dc97c178bf9f2e39796a7600d5182e22961b6 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 10 Jul 2025 08:48:42 -0600 Subject: [PATCH 2/5] Set ulimit (#19086) * Add script to set ulimits in case they are too low * Run the script * Set version * Set limit if it is too low --- Makefile | 2 +- .../rootfs/etc/s6-overlay/s6-rc.d/frigate/run | 1 + .../rootfs/usr/local/ulimit/set_ulimit.sh | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 docker/main/rootfs/usr/local/ulimit/set_ulimit.sh diff --git a/Makefile b/Makefile index b7c6ab821..80cbb519f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ default_target: local COMMIT_HASH := $(shell git log -1 --pretty=format:"%h"|tail -1) -VERSION = 0.15.0 +VERSION = 0.15.2 IMAGE_REPO ?= ghcr.io/blakeblackshear/frigate GITHUB_REF_NAME ?= $(shell git rev-parse --abbrev-ref HEAD) BOARDS= #Initialized empty diff --git a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run index e4a1b20e5..a42afe300 100755 --- a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run +++ b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run @@ -50,6 +50,7 @@ function set_libva_version() { echo "[INFO] Preparing Frigate..." migrate_db_path set_libva_version +/usr/local/ulimit/set_ulimit.sh echo "[INFO] Starting Frigate..." cd /opt/frigate || echo "[ERROR] Failed to change working directory to /opt/frigate" diff --git a/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh b/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh new file mode 100755 index 000000000..6c1bacfa2 --- /dev/null +++ b/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Newer versions of containerd 2.X+ impose a very low soft file limit of 1024 +# This applies to OSs like HA OS (see https://github.com/home-assistant/operating-system/issues/4110) +# Attempt to increase this limit + +# Get current soft and hard nofile limits +current_soft_limit=$(ulimit -Sn) +current_hard_limit=$(ulimit -Hn) + +TARGET_SOFT_LIMIT=65536 +TARGET_HARD_LIMIT=65536 + +if [ "$current_soft_limit" -lt "$TARGET_SOFT_LIMIT" ]; then + # Attempt to set both soft and hard limits to the new value + # This requires sufficient privileges (e.g., running as root in the container) + if ulimit -n "$TARGET_SOFT_LIMIT:$TARGET_HARD_LIMIT"; then + new_soft_limit=$(ulimit -Sn) + new_hard_limit=$(ulimit -Hn) + + if [ "$new_soft_limit" -ne "$TARGET_SOFT_LIMIT" ] || [ "$new_hard_limit" -ne "$TARGET_HARD_LIMIT" ]; then + echo "Warning: Limits were set, but not to the exact target values. Check system constraints." + fi + else + echo "Error: Failed to set new nofile limits." + fi +fi \ No newline at end of file From 95daf0ba05cf847f2f9ba493954cb73290a2d3c6 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 10 Jul 2025 10:54:47 -0600 Subject: [PATCH 3/5] Fix ulimit setting (#19087) * Fix setting both hard and soft limits * Clarify warning --- docker/main/rootfs/usr/local/ulimit/set_ulimit.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh b/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh index 6c1bacfa2..e5d1800a0 100755 --- a/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh +++ b/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh @@ -14,14 +14,14 @@ TARGET_HARD_LIMIT=65536 if [ "$current_soft_limit" -lt "$TARGET_SOFT_LIMIT" ]; then # Attempt to set both soft and hard limits to the new value # This requires sufficient privileges (e.g., running as root in the container) - if ulimit -n "$TARGET_SOFT_LIMIT:$TARGET_HARD_LIMIT"; then + if ulimit -Hn "$TARGET_HARD" && ulimit -Sn "$TARGET_SOFT"; then new_soft_limit=$(ulimit -Sn) new_hard_limit=$(ulimit -Hn) if [ "$new_soft_limit" -ne "$TARGET_SOFT_LIMIT" ] || [ "$new_hard_limit" -ne "$TARGET_HARD_LIMIT" ]; then - echo "Warning: Limits were set, but not to the exact target values. Check system constraints." + echo "Warning: Nofile limits were set, but not to the exact target values." fi else - echo "Error: Failed to set new nofile limits." + echo "Warning: Failed to set new nofile limits." fi fi \ No newline at end of file From 687e118b58479b8293c6d21ad729ed6de2e0d60c Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 10 Jul 2025 18:47:31 -0500 Subject: [PATCH 4/5] Fix ulimit script (#19095) * Fix ulimit script * still try to set soft limit --- .../rootfs/usr/local/ulimit/set_ulimit.sh | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh b/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh index e5d1800a0..fd172735f 100755 --- a/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh +++ b/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh @@ -11,17 +11,47 @@ current_hard_limit=$(ulimit -Hn) TARGET_SOFT_LIMIT=65536 TARGET_HARD_LIMIT=65536 -if [ "$current_soft_limit" -lt "$TARGET_SOFT_LIMIT" ]; then - # Attempt to set both soft and hard limits to the new value - # This requires sufficient privileges (e.g., running as root in the container) - if ulimit -Hn "$TARGET_HARD" && ulimit -Sn "$TARGET_SOFT"; then - new_soft_limit=$(ulimit -Sn) - new_hard_limit=$(ulimit -Hn) +echo "Current file limits - Soft: $current_soft_limit, Hard: $current_hard_limit" - if [ "$new_soft_limit" -ne "$TARGET_SOFT_LIMIT" ] || [ "$new_hard_limit" -ne "$TARGET_HARD_LIMIT" ]; then - echo "Warning: Nofile limits were set, but not to the exact target values." +if [ "$current_soft_limit" -lt "$TARGET_SOFT_LIMIT" ]; then + # Set hard limit first (if it needs to be increased) + hard_limit_success=true + if [ "$current_hard_limit" -lt "$TARGET_HARD_LIMIT" ]; then + if ! ulimit -Hn "$TARGET_HARD_LIMIT"; then + echo "Warning: Failed to set hard limit to $TARGET_HARD_LIMIT" + echo "Current hard limit is $current_hard_limit, will try to set soft limit anyway" + hard_limit_success=false fi - else - echo "Warning: Failed to set new nofile limits." fi + + # Determine what soft limit to use + if [ "$hard_limit_success" = true ] || [ "$current_hard_limit" -ge "$TARGET_SOFT_LIMIT" ]; then + # We can try to set the target soft limit + target_soft=$TARGET_SOFT_LIMIT + else + # Hard limit is too low, set soft limit to current hard limit + target_soft=$current_hard_limit + echo "Setting soft limit to current hard limit ($current_hard_limit) since hard limit couldn't be increased" + fi + + # Set soft limit + if ! ulimit -Sn "$target_soft"; then + echo "Warning: Failed to set soft limit to $target_soft" + exit 1 + fi + + # Verify the new limits + new_soft_limit=$(ulimit -Sn) + new_hard_limit=$(ulimit -Hn) + echo "New limits - Soft: $new_soft_limit, Hard: $new_hard_limit" + + if [ "$new_soft_limit" -eq "$TARGET_SOFT_LIMIT" ] && [ "$new_hard_limit" -eq "$TARGET_HARD_LIMIT" ]; then + echo "Successfully set file limits to target values" + elif [ "$new_soft_limit" -gt "$current_soft_limit" ]; then + echo "Successfully increased soft limit from $current_soft_limit to $new_soft_limit" + else + echo "Warning: Soft limit may not have been increased as expected" + fi +else + echo "Soft limit is already sufficient ($current_soft_limit >= $TARGET_SOFT_LIMIT)" fi \ No newline at end of file From 3bda638678fd8b33f93954a353660b48b3152efc Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Fri, 11 Jul 2025 08:11:35 -0500 Subject: [PATCH 5/5] Set ulimit with Python (#19105) * Set ulimit with python instead of in s6 startup * move to services and add env var * add comment --- .../rootfs/etc/s6-overlay/s6-rc.d/frigate/run | 1 - .../rootfs/usr/local/ulimit/set_ulimit.sh | 57 ------------------- frigate/app.py | 4 ++ frigate/util/services.py | 17 ++++++ 4 files changed, 21 insertions(+), 58 deletions(-) delete mode 100755 docker/main/rootfs/usr/local/ulimit/set_ulimit.sh diff --git a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run index a42afe300..e4a1b20e5 100755 --- a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run +++ b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run @@ -50,7 +50,6 @@ function set_libva_version() { echo "[INFO] Preparing Frigate..." migrate_db_path set_libva_version -/usr/local/ulimit/set_ulimit.sh echo "[INFO] Starting Frigate..." cd /opt/frigate || echo "[ERROR] Failed to change working directory to /opt/frigate" diff --git a/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh b/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh deleted file mode 100755 index fd172735f..000000000 --- a/docker/main/rootfs/usr/local/ulimit/set_ulimit.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -# Newer versions of containerd 2.X+ impose a very low soft file limit of 1024 -# This applies to OSs like HA OS (see https://github.com/home-assistant/operating-system/issues/4110) -# Attempt to increase this limit - -# Get current soft and hard nofile limits -current_soft_limit=$(ulimit -Sn) -current_hard_limit=$(ulimit -Hn) - -TARGET_SOFT_LIMIT=65536 -TARGET_HARD_LIMIT=65536 - -echo "Current file limits - Soft: $current_soft_limit, Hard: $current_hard_limit" - -if [ "$current_soft_limit" -lt "$TARGET_SOFT_LIMIT" ]; then - # Set hard limit first (if it needs to be increased) - hard_limit_success=true - if [ "$current_hard_limit" -lt "$TARGET_HARD_LIMIT" ]; then - if ! ulimit -Hn "$TARGET_HARD_LIMIT"; then - echo "Warning: Failed to set hard limit to $TARGET_HARD_LIMIT" - echo "Current hard limit is $current_hard_limit, will try to set soft limit anyway" - hard_limit_success=false - fi - fi - - # Determine what soft limit to use - if [ "$hard_limit_success" = true ] || [ "$current_hard_limit" -ge "$TARGET_SOFT_LIMIT" ]; then - # We can try to set the target soft limit - target_soft=$TARGET_SOFT_LIMIT - else - # Hard limit is too low, set soft limit to current hard limit - target_soft=$current_hard_limit - echo "Setting soft limit to current hard limit ($current_hard_limit) since hard limit couldn't be increased" - fi - - # Set soft limit - if ! ulimit -Sn "$target_soft"; then - echo "Warning: Failed to set soft limit to $target_soft" - exit 1 - fi - - # Verify the new limits - new_soft_limit=$(ulimit -Sn) - new_hard_limit=$(ulimit -Hn) - echo "New limits - Soft: $new_soft_limit, Hard: $new_hard_limit" - - if [ "$new_soft_limit" -eq "$TARGET_SOFT_LIMIT" ] && [ "$new_hard_limit" -eq "$TARGET_HARD_LIMIT" ]; then - echo "Successfully set file limits to target values" - elif [ "$new_soft_limit" -gt "$current_soft_limit" ]; then - echo "Successfully increased soft limit from $current_soft_limit to $new_soft_limit" - else - echo "Warning: Soft limit may not have been increased as expected" - fi -else - echo "Soft limit is already sufficient ($current_soft_limit >= $TARGET_SOFT_LIMIT)" -fi \ No newline at end of file diff --git a/frigate/app.py b/frigate/app.py index 02955b6c9..23facba40 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -71,6 +71,7 @@ from frigate.timeline import TimelineProcessor from frigate.util.builtin import empty_and_close_queue from frigate.util.image import SharedMemoryFrameManager, UntrackedSharedMemory from frigate.util.object import get_camera_regions_grid +from frigate.util.services import set_file_limit from frigate.version import VERSION from frigate.video import capture_camera, track_camera from frigate.watchdog import FrigateWatchdog @@ -587,6 +588,9 @@ class FrigateApp: # Ensure global state. self.ensure_dirs() + # Set soft file limits. + set_file_limit() + # Start frigate services. self.init_camera_metrics() self.init_queues() diff --git a/frigate/util/services.py b/frigate/util/services.py index 2fd701298..cb573a331 100644 --- a/frigate/util/services.py +++ b/frigate/util/services.py @@ -5,6 +5,7 @@ import json import logging import os import re +import resource import signal import subprocess as sp import traceback @@ -632,3 +633,19 @@ async def get_video_properties( result["fourcc"] = fourcc return result + + +def set_file_limit() -> None: + # Newer versions of containerd 2.X+ impose a very low soft file limit of 1024 + # This applies to OSs like HA OS (see https://github.com/home-assistant/operating-system/issues/4110) + # Attempt to increase this limit + soft_limit = int(os.getenv("SOFT_FILE_LIMIT", "65536") or "65536") + + current_soft, current_hard = resource.getrlimit(resource.RLIMIT_NOFILE) + logger.info(f"Current file limits - Soft: {current_soft}, Hard: {current_hard}") + + new_soft = min(soft_limit, current_hard) + resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft, current_hard)) + logger.info( + f"File limit set. New soft limit: {new_soft}, Hard limit remains: {current_hard}" + )