mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-05-01 19:17:41 +03:00
Start Frigate in safe mode when config does not validate
This commit is contained in:
parent
3892f8c732
commit
acefab19b2
@ -93,7 +93,14 @@ def main() -> None:
|
|||||||
print("*************************************************************")
|
print("*************************************************************")
|
||||||
print("*** End Config Validation Errors ***")
|
print("*** End Config Validation Errors ***")
|
||||||
print("*************************************************************")
|
print("*************************************************************")
|
||||||
sys.exit(1)
|
|
||||||
|
# attempt to start Frigate in recovery mode
|
||||||
|
try:
|
||||||
|
config = FrigateConfig.load(install=True, safe_load=True)
|
||||||
|
print("Starting Frigate in safe mode.")
|
||||||
|
except ValidationError:
|
||||||
|
print("Unable to load minimal Frigate config.")
|
||||||
|
sys.exit(1)
|
||||||
if args.validate_config:
|
if args.validate_config:
|
||||||
print("*************************************************************")
|
print("*************************************************************")
|
||||||
print("*** Your config file is valid. ***")
|
print("*** Your config file is valid. ***")
|
||||||
|
|||||||
@ -334,6 +334,9 @@ def verify_lpr_and_face(
|
|||||||
|
|
||||||
class FrigateConfig(FrigateBaseModel):
|
class FrigateConfig(FrigateBaseModel):
|
||||||
version: Optional[str] = Field(default=None, title="Current config version.")
|
version: Optional[str] = Field(default=None, title="Current config version.")
|
||||||
|
safe_mode: bool = Field(
|
||||||
|
default=False, title="If Frigate should be started in safe mode."
|
||||||
|
)
|
||||||
|
|
||||||
# Fields that install global state should be defined first, so that their validators run first.
|
# Fields that install global state should be defined first, so that their validators run first.
|
||||||
environment_vars: EnvVars = Field(
|
environment_vars: EnvVars = Field(
|
||||||
@ -716,6 +719,7 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, **kwargs):
|
def load(cls, **kwargs):
|
||||||
|
"""Loads the Frigate config file, runs migrations, and creates the config object."""
|
||||||
config_path = find_config_file()
|
config_path = find_config_file()
|
||||||
|
|
||||||
# No configuration file found, create one.
|
# No configuration file found, create one.
|
||||||
@ -743,7 +747,7 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
return FrigateConfig.parse(f, **kwargs)
|
return FrigateConfig.parse(f, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse(cls, config, *, is_json=None, **context):
|
def parse(cls, config, *, is_json=None, safe_load=False, **context):
|
||||||
# If config is a file, read its contents.
|
# If config is a file, read its contents.
|
||||||
if hasattr(config, "read"):
|
if hasattr(config, "read"):
|
||||||
fname = getattr(config, "name", None)
|
fname = getattr(config, "name", None)
|
||||||
@ -767,6 +771,15 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
else:
|
else:
|
||||||
config = yaml.load(config)
|
config = yaml.load(config)
|
||||||
|
|
||||||
|
# load minimal Frigate config after the full config did not validate
|
||||||
|
if safe_load:
|
||||||
|
safe_config = {"safe_mode": True, "cameras": {}, "mqtt": {"enabled": False}}
|
||||||
|
|
||||||
|
# copy over auth and proxy config in case auth needs to be enforced
|
||||||
|
safe_config["auth"] = config.get("auth", {})
|
||||||
|
safe_config["proxy"] = config.get("proxy", {})
|
||||||
|
return cls.parse_object(safe_config, **context)
|
||||||
|
|
||||||
# Validate and return the config dict.
|
# Validate and return the config dict.
|
||||||
return cls.parse_object(config, **context)
|
return cls.parse_object(config, **context)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user