mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-06-21 11:51:53 +03:00
restore on startup with special case for profile
This commit is contained in:
parent
57280a1d9e
commit
f46eed2863
@ -908,6 +908,11 @@ def config_set(request: Request, body: AppConfigSetBody):
|
|||||||
status_code=500,
|
status_code=500,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# drop runtime overrides for any fields the user just rewrote in
|
||||||
|
# yaml so a stale override doesn't silently win after restart
|
||||||
|
if request.app.dispatcher is not None:
|
||||||
|
request.app.dispatcher.clear_runtime_state_for_yaml_keys(updates.keys())
|
||||||
|
|
||||||
if body.requires_restart == 0 or body.update_topic:
|
if body.requires_restart == 0 or body.update_topic:
|
||||||
old_config: FrigateConfig = request.app.frigate_config
|
old_config: FrigateConfig = request.app.frigate_config
|
||||||
request.app.frigate_config = config
|
request.app.frigate_config = config
|
||||||
|
|||||||
@ -348,7 +348,11 @@ class FrigateApp:
|
|||||||
persisted in cam.profiles for cam in self.config.cameras.values()
|
persisted in cam.profiles for cam in self.config.cameras.values()
|
||||||
):
|
):
|
||||||
logger.info("Restoring persisted profile '%s'", persisted)
|
logger.info("Restoring persisted profile '%s'", persisted)
|
||||||
self.profile_manager.activate_profile(persisted)
|
# don't clear runtime overrides here, restore_runtime_state() later
|
||||||
|
# in startup replays it on top of the activated profile
|
||||||
|
self.profile_manager.activate_profile(
|
||||||
|
persisted, clear_runtime_overrides=False
|
||||||
|
)
|
||||||
|
|
||||||
def start_detectors(self) -> None:
|
def start_detectors(self) -> None:
|
||||||
for name in self.config.cameras.keys():
|
for name in self.config.cameras.keys():
|
||||||
@ -612,6 +616,9 @@ class FrigateApp:
|
|||||||
self.start_record_cleanup()
|
self.start_record_cleanup()
|
||||||
self.start_watchdog()
|
self.start_watchdog()
|
||||||
|
|
||||||
|
# restore persisted runtime overrides on top of config
|
||||||
|
self.dispatcher.restore_runtime_state()
|
||||||
|
|
||||||
self.init_auth()
|
self.init_auth()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -124,11 +124,24 @@ class ProfileManager:
|
|||||||
self.config.active_profile = None
|
self.config.active_profile = None
|
||||||
self._persist_active_profile(None)
|
self._persist_active_profile(None)
|
||||||
|
|
||||||
def activate_profile(self, profile_name: Optional[str]) -> Optional[str]:
|
# drop all runtime overrides so they don't replay stale values on restart
|
||||||
|
if self.dispatcher is not None:
|
||||||
|
self.dispatcher.clear_runtime_state()
|
||||||
|
|
||||||
|
def activate_profile(
|
||||||
|
self,
|
||||||
|
profile_name: Optional[str],
|
||||||
|
clear_runtime_overrides: bool = True,
|
||||||
|
) -> Optional[str]:
|
||||||
"""Activate a profile by name, or deactivate if None.
|
"""Activate a profile by name, or deactivate if None.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
profile_name: Profile name to activate, or None to deactivate.
|
profile_name: Profile name to activate, or None to deactivate.
|
||||||
|
clear_runtime_overrides: When True (the default, for user-initiated
|
||||||
|
activations) drop the dispatcher's runtime override file because
|
||||||
|
the layer below changed. Startup callers that are replaying a
|
||||||
|
persisted profile pass False so the runtime state stays
|
||||||
|
available for the subsequent replay step.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
None on success, or an error message string on failure.
|
None on success, or an error message string on failure.
|
||||||
@ -156,6 +169,11 @@ class ProfileManager:
|
|||||||
|
|
||||||
self.config.active_profile = profile_name
|
self.config.active_profile = profile_name
|
||||||
self._persist_active_profile(profile_name)
|
self._persist_active_profile(profile_name)
|
||||||
|
|
||||||
|
# a profile switch invalidates the steady-state runtime overrides
|
||||||
|
if clear_runtime_overrides and self.dispatcher is not None:
|
||||||
|
self.dispatcher.clear_runtime_state()
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Profile %s",
|
"Profile %s",
|
||||||
f"'{profile_name}' activated" if profile_name else "deactivated",
|
f"'{profile_name}' activated" if profile_name else "deactivated",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user