mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-01-11 17:27:42 +08:00
WIP
This commit is contained in:
parent
5a93456dcd
commit
1cb0799d23
2 changed files with 78 additions and 73 deletions
|
@ -64,15 +64,15 @@ def authenticate(actual_method):
|
|||
class Shutdown(Resource):
|
||||
@authenticate
|
||||
def get(self):
|
||||
from main import Server
|
||||
Server.shutdown()
|
||||
from main import webserver
|
||||
webserver.shutdown()
|
||||
|
||||
|
||||
class Restart(Resource):
|
||||
@authenticate
|
||||
def get(self):
|
||||
from main import Server
|
||||
Server.restart()
|
||||
from main import webserver
|
||||
webserver.restart()
|
||||
|
||||
|
||||
class Badges(Resource):
|
||||
|
|
|
@ -464,7 +464,9 @@ def test_notification(protocol, provider):
|
|||
return '', 200
|
||||
|
||||
|
||||
class Server:
|
||||
class Server(object):
|
||||
class __Server:
|
||||
def __init__(self):
|
||||
# Mute DeprecationWarning
|
||||
warnings.simplefilter("ignore", DeprecationWarning)
|
||||
# Mute Insecure HTTPS requests made to Sonarr and Radarr
|
||||
|
@ -473,38 +475,27 @@ class Server:
|
|||
warnings.simplefilter("ignore", BrokenPipeError)
|
||||
|
||||
if args.dev:
|
||||
server = app.run(host=str(settings.general.ip),
|
||||
self.server = app.run(host=str(settings.general.ip),
|
||||
port=(int(args.port) if args.port else int(settings.general.port)))
|
||||
else:
|
||||
server = create_server(app,
|
||||
self.server = create_server(app,
|
||||
host=str(settings.general.ip),
|
||||
port=int(args.port) if args.port else int(settings.general.port),
|
||||
threads=24)
|
||||
|
||||
# Make sure that server class instance isn't getting instantiated again but reused instead.
|
||||
_instance = None
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if not cls._instance:
|
||||
cls._instance = super(Server, cls).__new__(
|
||||
cls, *args, **kwargs)
|
||||
return cls._instance
|
||||
|
||||
@classmethod
|
||||
def start(cls):
|
||||
def start(self):
|
||||
try:
|
||||
logging.info(
|
||||
'BAZARR is started and waiting for request on http://' + str(settings.general.ip) + ':' + (str(
|
||||
args.port) if args.port else str(settings.general.port)) + str(base_url))
|
||||
if not args.dev:
|
||||
cls.server.run()
|
||||
self.server.run()
|
||||
except KeyboardInterrupt:
|
||||
cls.shutdown()
|
||||
self.shutdown()
|
||||
|
||||
@classmethod
|
||||
def shutdown(cls):
|
||||
def shutdown(self):
|
||||
try:
|
||||
cls.server.close()
|
||||
self.server.close()
|
||||
except Exception as e:
|
||||
logging.error('BAZARR Cannot stop Waitress: ' + repr(e))
|
||||
else:
|
||||
|
@ -519,10 +510,9 @@ class Server:
|
|||
stop_file.close()
|
||||
os._exit(0)
|
||||
|
||||
@classmethod
|
||||
def restart(cls):
|
||||
def restart(self):
|
||||
try:
|
||||
cls.server.close()
|
||||
self.server.close()
|
||||
except Exception as e:
|
||||
logging.error('BAZARR Cannot stop Waitress: ' + repr(e))
|
||||
else:
|
||||
|
@ -537,6 +527,21 @@ class Server:
|
|||
restart_file.close()
|
||||
os._exit(0)
|
||||
|
||||
instance = None
|
||||
|
||||
def __new__(cls): # __new__ always a classmethod
|
||||
if not Server.instance:
|
||||
Server.instance = Server.__Server()
|
||||
return Server.instance
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.instance, name)
|
||||
|
||||
def __setattr__(self, name):
|
||||
return setattr(self.instance, name)
|
||||
|
||||
|
||||
webserver = Server()
|
||||
|
||||
if __name__ == "__main__":
|
||||
Server.start()
|
||||
webserver.start()
|
||||
|
|
Loading…
Reference in a new issue