mirror of
				https://github.com/blakeblackshear/frigate.git
				synced 2025-10-27 10:52:11 +01:00 
			
		
		
		
	* Moved FrigateApp.init_config() into FrigateConfig.load() * Move frigate config loading into main * Store PlusApi in FrigateConfig * Register SIGTERM handler in main * Ensure logging is setup during config parsing * Removed pointless try * Moved config initialization out of FrigateApp * Made FrigateApp.shm_frame_count into a function * Removed log calls from signal handlers python's logging calls are not re-entrant, which caused at least one of these to deadlock randomly. * Reopen stdout/err on process fork This helps avoid deadlocks (https://github.com/python/cpython/issues/91776). * Make mypy happy * Whoops. I might have forgotten to save. Truly an amateur mistake. * Always call FrigateApp.stop()
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
"""Run recording maintainer and cleanup."""
 | 
						|
 | 
						|
import logging
 | 
						|
import multiprocessing as mp
 | 
						|
import signal
 | 
						|
import threading
 | 
						|
from types import FrameType
 | 
						|
from typing import Optional
 | 
						|
 | 
						|
from playhouse.sqliteq import SqliteQueueDatabase
 | 
						|
from setproctitle import setproctitle
 | 
						|
 | 
						|
from frigate.config import FrigateConfig
 | 
						|
from frigate.models import Recordings, ReviewSegment
 | 
						|
from frigate.record.maintainer import RecordingMaintainer
 | 
						|
from frigate.util.services import listen
 | 
						|
 | 
						|
logger = logging.getLogger(__name__)
 | 
						|
 | 
						|
 | 
						|
def manage_recordings(config: FrigateConfig) -> None:
 | 
						|
    stop_event = mp.Event()
 | 
						|
 | 
						|
    def receiveSignal(signalNumber: int, frame: Optional[FrameType]) -> None:
 | 
						|
        stop_event.set()
 | 
						|
 | 
						|
    signal.signal(signal.SIGTERM, receiveSignal)
 | 
						|
    signal.signal(signal.SIGINT, receiveSignal)
 | 
						|
 | 
						|
    threading.current_thread().name = "process:recording_manager"
 | 
						|
    setproctitle("frigate.recording_manager")
 | 
						|
    listen()
 | 
						|
 | 
						|
    db = SqliteQueueDatabase(
 | 
						|
        config.database.path,
 | 
						|
        pragmas={
 | 
						|
            "auto_vacuum": "FULL",  # Does not defragment database
 | 
						|
            "cache_size": -512 * 1000,  # 512MB of cache
 | 
						|
            "synchronous": "NORMAL",  # Safe when using WAL https://www.sqlite.org/pragma.html#pragma_synchronous
 | 
						|
        },
 | 
						|
        timeout=max(60, 10 * len([c for c in config.cameras.values() if c.enabled])),
 | 
						|
    )
 | 
						|
    models = [ReviewSegment, Recordings]
 | 
						|
    db.bind(models)
 | 
						|
 | 
						|
    maintainer = RecordingMaintainer(
 | 
						|
        config,
 | 
						|
        stop_event,
 | 
						|
    )
 | 
						|
    maintainer.start()
 |