fix: port-in-use check and remove packaging dependency

This commit is contained in:
2026-03-28 18:52:46 +03:00
parent 98163ea5a9
commit 5219263388
4 changed files with 68 additions and 13 deletions
+14
View File
@@ -2,6 +2,7 @@
import argparse
import logging
import socket
import sys
from contextlib import asynccontextmanager
from pathlib import Path
@@ -259,6 +260,19 @@ def main():
print("\nAuthentication is DISABLED (no tokens configured)")
return
# Check if port is available before starting
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
try:
sock.bind((args.host if args.host != "0.0.0.0" else "127.0.0.1", args.port))
except OSError:
print(
f"ERROR: Port {args.port} is already in use. "
f"Another instance of Media Server may be running.\n"
f"Stop the other process or use --port to pick a different port.",
file=sys.stderr,
)
sys.exit(1)
from .tray import PYSTRAY_AVAILABLE, TrayManager
use_tray = PYSTRAY_AVAILABLE and not args.no_tray