mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-10 07:33:00 +03:00
write migrated config atomically
Config migration rewrote config.yml in place with open("w") after each step, so nginx's get_nginx_settings.py, which starts alongside frigate, could read an empty file, get None from yaml.load, and crash on config.get. Each step now writes to a temp file with the original mode and os.replace's it into place.
This commit is contained in:
+17
-18
@@ -212,6 +212,14 @@ def find_config_file() -> str:
|
|||||||
return config_path
|
return config_path
|
||||||
|
|
||||||
|
|
||||||
|
def _write_config(config_file: str, yaml: YAML, config: dict[str, Any]) -> None:
|
||||||
|
tmp_file = f"{config_file}.tmp"
|
||||||
|
with open(tmp_file, "w") as f:
|
||||||
|
yaml.dump(config, f)
|
||||||
|
shutil.copymode(config_file, tmp_file)
|
||||||
|
os.replace(tmp_file, config_file)
|
||||||
|
|
||||||
|
|
||||||
def migrate_frigate_config(config_file: str):
|
def migrate_frigate_config(config_file: str):
|
||||||
"""handle migrating the frigate config."""
|
"""handle migrating the frigate config."""
|
||||||
logger.info("Checking if frigate config needs migration...")
|
logger.info("Checking if frigate config needs migration...")
|
||||||
@@ -259,8 +267,7 @@ def migrate_frigate_config(config_file: str):
|
|||||||
if previous_version < "0.14":
|
if previous_version < "0.14":
|
||||||
logger.info(f"Migrating frigate config from {previous_version} to 0.14...")
|
logger.info(f"Migrating frigate config from {previous_version} to 0.14...")
|
||||||
new_config = migrate_014(new_config)
|
new_config = migrate_014(new_config)
|
||||||
with open(config_file, "w") as f:
|
_write_config(config_file, yaml, new_config)
|
||||||
yaml.dump(new_config, f)
|
|
||||||
previous_version = "0.14"
|
previous_version = "0.14"
|
||||||
|
|
||||||
logger.info("Migrating export file names...")
|
logger.info("Migrating export file names...")
|
||||||
@@ -277,56 +284,48 @@ def migrate_frigate_config(config_file: str):
|
|||||||
if previous_version < "0.15-0":
|
if previous_version < "0.15-0":
|
||||||
logger.info(f"Migrating frigate config from {previous_version} to 0.15-0...")
|
logger.info(f"Migrating frigate config from {previous_version} to 0.15-0...")
|
||||||
new_config = migrate_015_0(new_config)
|
new_config = migrate_015_0(new_config)
|
||||||
with open(config_file, "w") as f:
|
_write_config(config_file, yaml, new_config)
|
||||||
yaml.dump(new_config, f)
|
|
||||||
previous_version = "0.15-0"
|
previous_version = "0.15-0"
|
||||||
|
|
||||||
if previous_version < "0.15-1":
|
if previous_version < "0.15-1":
|
||||||
logger.info(f"Migrating frigate config from {previous_version} to 0.15-1...")
|
logger.info(f"Migrating frigate config from {previous_version} to 0.15-1...")
|
||||||
new_config = migrate_015_1(new_config)
|
new_config = migrate_015_1(new_config)
|
||||||
with open(config_file, "w") as f:
|
_write_config(config_file, yaml, new_config)
|
||||||
yaml.dump(new_config, f)
|
|
||||||
previous_version = "0.15-1"
|
previous_version = "0.15-1"
|
||||||
|
|
||||||
if previous_version < "0.16-0":
|
if previous_version < "0.16-0":
|
||||||
logger.info(f"Migrating frigate config from {previous_version} to 0.16-0...")
|
logger.info(f"Migrating frigate config from {previous_version} to 0.16-0...")
|
||||||
new_config = migrate_016_0(new_config)
|
new_config = migrate_016_0(new_config)
|
||||||
with open(config_file, "w") as f:
|
_write_config(config_file, yaml, new_config)
|
||||||
yaml.dump(new_config, f)
|
|
||||||
previous_version = "0.16-0"
|
previous_version = "0.16-0"
|
||||||
|
|
||||||
if previous_version < "0.17-0":
|
if previous_version < "0.17-0":
|
||||||
logger.info(f"Migrating frigate config from {previous_version} to 0.17-0...")
|
logger.info(f"Migrating frigate config from {previous_version} to 0.17-0...")
|
||||||
new_config = migrate_017_0(new_config)
|
new_config = migrate_017_0(new_config)
|
||||||
with open(config_file, "w") as f:
|
_write_config(config_file, yaml, new_config)
|
||||||
yaml.dump(new_config, f)
|
|
||||||
previous_version = "0.17-0"
|
previous_version = "0.17-0"
|
||||||
|
|
||||||
if previous_version < "0.18-0":
|
if previous_version < "0.18-0":
|
||||||
logger.info(f"Migrating frigate config from {previous_version} to 0.18-0...")
|
logger.info(f"Migrating frigate config from {previous_version} to 0.18-0...")
|
||||||
new_config = migrate_018_0(new_config)
|
new_config = migrate_018_0(new_config)
|
||||||
with open(config_file, "w") as f:
|
_write_config(config_file, yaml, new_config)
|
||||||
yaml.dump(new_config, f)
|
|
||||||
previous_version = "0.18-0"
|
previous_version = "0.18-0"
|
||||||
|
|
||||||
if previous_version < "0.19-0":
|
if previous_version < "0.19-0":
|
||||||
logger.info(f"Migrating frigate config from {previous_version} to 0.19-0...")
|
logger.info(f"Migrating frigate config from {previous_version} to 0.19-0...")
|
||||||
new_config = migrate_019_0(new_config)
|
new_config = migrate_019_0(new_config)
|
||||||
with open(config_file, "w") as f:
|
_write_config(config_file, yaml, new_config)
|
||||||
yaml.dump(new_config, f)
|
|
||||||
previous_version = "0.19-0"
|
previous_version = "0.19-0"
|
||||||
|
|
||||||
if needs_models:
|
if needs_models:
|
||||||
logger.info("Migrating frigate detectors and model to models...")
|
logger.info("Migrating frigate detectors and model to models...")
|
||||||
new_config = migrate_models(new_config)
|
new_config = migrate_models(new_config)
|
||||||
with open(config_file, "w") as f:
|
_write_config(config_file, yaml, new_config)
|
||||||
yaml.dump(new_config, f)
|
|
||||||
|
|
||||||
if needs_detector_rename:
|
if needs_detector_rename:
|
||||||
logger.info("Migrating renamed frigate detectors...")
|
logger.info("Migrating renamed frigate detectors...")
|
||||||
new_config = rename_hailo_detector(new_config)
|
new_config = rename_hailo_detector(new_config)
|
||||||
with open(config_file, "w") as f:
|
_write_config(config_file, yaml, new_config)
|
||||||
yaml.dump(new_config, f)
|
|
||||||
|
|
||||||
logger.info("Finished frigate config migration...")
|
logger.info("Finished frigate config migration...")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user