video_monitor/app/management/commands/runservices.py

28 lines
900 B
Python
Raw Normal View History

2026-08-30 22:22:11 +08:00
import signal
import threading
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = "Run SIP, ZLM ownership, recording, auto-proxy, and opt-in heartbeat as one leader"
def handle(self, *args, **options):
from app.services.lifecycle import get_service_manager
manager = get_service_manager()
if not manager.start():
raise CommandError("another process already owns the background-service leader lock")
stop = threading.Event()
def _shutdown(*_args):
stop.set()
for signum in (signal.SIGINT, signal.SIGTERM):
try:
signal.signal(signum, _shutdown)
except (ValueError, OSError):
pass
self.stdout.write(self.style.SUCCESS("background services running as leader"))
stop.wait()
manager.stop()