Set ulimit with Python (#19105)

* Set ulimit with python instead of in s6 startup

* move to services and add env var

* add comment
This commit is contained in:
Josh Hawkins
2025-07-11 08:11:35 -05:00
committed by GitHub
parent 687e118b58
commit 3bda638678
4 changed files with 21 additions and 58 deletions
+4
View File
@@ -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()
+17
View File
@@ -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}"
)