mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-01-09 08:17:42 +08:00
Fixed incorrect IP or already used TCP port from preventing Bazarr initialization.
This commit is contained in:
parent
fa8ddeb2aa
commit
7a2d2399fc
2 changed files with 32 additions and 8 deletions
|
@ -1,7 +1,6 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
|
||||||
from flask import Flask, redirect
|
from flask import Flask, redirect
|
||||||
import os
|
|
||||||
|
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
from flask_socketio import SocketIO
|
from flask_socketio import SocketIO
|
||||||
|
|
|
@ -4,8 +4,10 @@ import warnings
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
|
import errno
|
||||||
|
|
||||||
from waitress.server import create_server
|
from waitress.server import create_server
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
from api import api_bp_list
|
from api import api_bp_list
|
||||||
from .ui import ui_bp
|
from .ui import ui_bp
|
||||||
|
@ -31,16 +33,39 @@ class Server:
|
||||||
# Mute Python3 BrokenPipeError
|
# Mute Python3 BrokenPipeError
|
||||||
warnings.simplefilter("ignore", BrokenPipeError)
|
warnings.simplefilter("ignore", BrokenPipeError)
|
||||||
|
|
||||||
|
self.server = None
|
||||||
|
self.connected = False
|
||||||
|
self.address = str(settings.general.ip)
|
||||||
|
self.port = int(args.port) if args.port else int(settings.general.port)
|
||||||
|
|
||||||
|
while not self.connected:
|
||||||
|
sleep(0.1)
|
||||||
|
self.configure_server()
|
||||||
|
|
||||||
|
def configure_server(self):
|
||||||
|
try:
|
||||||
self.server = create_server(app,
|
self.server = create_server(app,
|
||||||
host=str(settings.general.ip),
|
host=self.address,
|
||||||
port=int(args.port) if args.port else int(settings.general.port),
|
port=self.port,
|
||||||
threads=100)
|
threads=100)
|
||||||
|
self.connected = True
|
||||||
|
except OSError as error:
|
||||||
|
if error.errno == errno.EADDRNOTAVAIL:
|
||||||
|
logging.exception("BAZARR cannot bind to specified IP, trying with default (0.0.0.0)")
|
||||||
|
self.address = '0.0.0.0'
|
||||||
|
self.connected = False
|
||||||
|
elif error.errno == errno.EADDRINUSE:
|
||||||
|
logging.exception("BAZARR cannot bind to specified TCP port, trying with default (6767)")
|
||||||
|
self.port = '6767'
|
||||||
|
self.connected = False
|
||||||
|
else:
|
||||||
|
logging.exception("BAZARR cannot start because of unhandled exception.")
|
||||||
|
self.shutdown()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
try:
|
try:
|
||||||
logging.info(
|
logging.info(f'BAZARR is started and waiting for request on http://{self.server.effective_host}:'
|
||||||
'BAZARR is started and waiting for request on http://' + str(settings.general.ip) + ':' + (str(
|
f'{self.server.effective_port}')
|
||||||
args.port) if args.port else str(settings.general.port)) + str(base_url))
|
|
||||||
try:
|
try:
|
||||||
self.server.run()
|
self.server.run()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
Loading…
Reference in a new issue