2024-09-24 14:07:47 +02:00
|
|
|
import argparse
|
2021-02-17 14:23:32 +01:00
|
|
|
import faulthandler
|
2024-09-17 15:26:25 +02:00
|
|
|
import logging
|
2024-09-24 14:07:47 +02:00
|
|
|
import signal
|
|
|
|
import sys
|
2023-05-29 12:31:17 +02:00
|
|
|
import threading
|
|
|
|
|
2024-09-24 14:07:47 +02:00
|
|
|
from pydantic import ValidationError
|
2021-02-17 14:23:32 +01:00
|
|
|
|
2024-06-23 15:13:02 +02:00
|
|
|
from frigate.app import FrigateApp
|
2024-09-24 14:07:47 +02:00
|
|
|
from frigate.config import FrigateConfig
|
|
|
|
from frigate.log import log_thread
|
2023-05-29 12:31:17 +02:00
|
|
|
|
2020-11-04 13:31:25 +01:00
|
|
|
|
2024-09-17 15:26:25 +02:00
|
|
|
def main() -> None:
|
|
|
|
faulthandler.enable()
|
2020-11-01 15:06:15 +01:00
|
|
|
|
2024-09-17 15:26:25 +02:00
|
|
|
# Clear all existing handlers.
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.INFO,
|
|
|
|
handlers=[],
|
|
|
|
force=True,
|
|
|
|
)
|
2020-11-04 04:26:39 +01:00
|
|
|
|
2024-09-17 15:26:25 +02:00
|
|
|
threading.current_thread().name = "frigate"
|
|
|
|
|
2024-09-24 14:07:47 +02:00
|
|
|
# Make sure we exit cleanly on SIGTERM.
|
|
|
|
signal.signal(signal.SIGTERM, lambda sig, frame: sys.exit())
|
|
|
|
|
|
|
|
run()
|
|
|
|
|
|
|
|
|
|
|
|
@log_thread()
|
|
|
|
def run() -> None:
|
|
|
|
# Parse the cli arguments.
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
prog="Frigate",
|
|
|
|
description="An NVR with realtime local object detection for IP cameras.",
|
|
|
|
)
|
|
|
|
parser.add_argument("--validate-config", action="store_true")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Load the configuration.
|
|
|
|
try:
|
|
|
|
config = FrigateConfig.load()
|
|
|
|
except ValidationError as e:
|
|
|
|
print("*************************************************************")
|
|
|
|
print("*************************************************************")
|
|
|
|
print("*** Your config file is not valid! ***")
|
|
|
|
print("*** Please check the docs at ***")
|
|
|
|
print("*** https://docs.frigate.video/configuration/ ***")
|
|
|
|
print("*************************************************************")
|
|
|
|
print("*************************************************************")
|
|
|
|
print("*** Config Validation Errors ***")
|
|
|
|
print("*************************************************************")
|
|
|
|
for error in e.errors():
|
|
|
|
location = ".".join(str(item) for item in error["loc"])
|
|
|
|
print(f"{location}: {error['msg']}")
|
|
|
|
print("*************************************************************")
|
|
|
|
print("*** End Config Validation Errors ***")
|
|
|
|
print("*************************************************************")
|
|
|
|
sys.exit(1)
|
|
|
|
if args.validate_config:
|
|
|
|
print("*************************************************************")
|
|
|
|
print("*** Your config file is valid. ***")
|
|
|
|
print("*************************************************************")
|
|
|
|
sys.exit(0)
|
|
|
|
|
2024-09-17 15:26:25 +02:00
|
|
|
# Run the main application.
|
2024-09-24 14:07:47 +02:00
|
|
|
FrigateApp(config).start()
|
2020-11-01 16:56:33 +01:00
|
|
|
|
2024-09-17 15:26:25 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|