From 247e2677f38126b89dfd08c4e6728059da7efc18 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sun, 20 Dec 2020 08:00:07 -0600 Subject: [PATCH] enable mounting tmpfs volume on start --- README.md | 4 ++++ frigate/app.py | 10 +++++++++- frigate/config.py | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25ec961bb..0ec96b7b8 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,10 @@ save_clips: # NOTE: If an object is being tracked for longer than this amount of time, the cache # will begin to expire and the resulting clip will be the last x seconds of the event. max_seconds: 300 + # Optional: size of tmpfs mount to create for cache files (default: not set) + # mount -t tmpfs -o size={tmpfs_cache_size} tmpfs /tmp/cache + # Notice: If you have mounted a tmpfs volume through docker, this value should not be set in your config + tmpfs_cache_size: 256m # Optional: Retention settings for clips (default: shown below) retain: # Required: Default retention days (default: shown below) diff --git a/frigate/app.py b/frigate/app.py index e8911c0c4..7ce4449db 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -38,6 +38,13 @@ class FrigateApp(): self.camera_metrics = {} def ensure_dirs(self): + tmpfs_size = self.config.save_clips.tmpfs_cache_size + if tmpfs_size: + logger.info(f"Creating tmpfs of size {tmpfs_size}") + rc = os.system(f"mount -t tmpfs -o size={tmpfs_size} tmpfs /tmp/cache") + if rc != 0: + logger.error(f"Failed to create tmpfs, error code: {rc}") + for d in [RECORD_DIR, CLIPS_DIR, CACHE_DIR]: if not os.path.exists(d) and not os.path.islink(d): logger.info(f"Creating directory: {d}") @@ -173,19 +180,20 @@ class FrigateApp(): def start(self): self.init_logger() try: - self.ensure_dirs() try: self.init_config() except Exception as e: logger.error(f"Error parsing config: {e}") self.log_process.terminate() sys.exit(1) + self.ensure_dirs() self.check_config() self.set_log_levels() self.init_queues() self.init_database() self.init_mqtt() except Exception as e: + print(e) logger.error(e) self.log_process.terminate() sys.exit(1) diff --git a/frigate/config.py b/frigate/config.py index 039fd86d0..f9b769f96 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -51,6 +51,7 @@ SAVE_CLIPS_RETAIN_SCHEMA = vol.Schema( SAVE_CLIPS_SCHEMA = vol.Schema( { vol.Optional('max_seconds', default=300): int, + 'tmpfs_cache_size': str, vol.Optional('retain', default={}): SAVE_CLIPS_RETAIN_SCHEMA } ) @@ -410,11 +411,16 @@ class SaveClipsRetainConfig(): class SaveClipsConfig(): def __init__(self, config): self._max_seconds = config['max_seconds'] + self._tmpfs_cache_size = config.get('tmpfs_cache_size', '').strip() self._retain = SaveClipsRetainConfig(config['retain'], config['retain']) @property def max_seconds(self): return self._max_seconds + + @property + def tmpfs_cache_size(self): + return self._tmpfs_cache_size @property def retain(self): @@ -423,6 +429,7 @@ class SaveClipsConfig(): def to_dict(self): return { 'max_seconds': self.max_seconds, + 'tmpfs_cache_size': self.tmpfs_cache_size, 'retain': self.retain.to_dict() }