pull/997/head
Louis Vézina 5 years ago
parent 823b4ee9b4
commit 5177214450

@ -64,15 +64,15 @@ def authenticate(actual_method):
class Shutdown(Resource): class Shutdown(Resource):
@authenticate @authenticate
def get(self): def get(self):
from main import webserver from main import Server
webserver.shutdown() Server.shutdown()
class Restart(Resource): class Restart(Resource):
@authenticate @authenticate
def get(self): def get(self):
from main import webserver from main import Server
webserver.restart() Server.restart()
class Badges(Resource): class Badges(Resource):

@ -283,12 +283,7 @@ def request_json(url, **kwargs):
def updated(restart=True): def updated(restart=True):
if settings.general.getboolean('update_restart') and restart: if settings.general.getboolean('update_restart') and restart:
try: from main import Server
requests.get('http://127.0.0.1:' + settings.general.port + settings.general.base_url + 'restart') Server.restart()
except requests.ConnectionError:
pass
except (requests.ConnectTimeout, requests.HTTPError, requests.ReadTimeout, requests.Timeout):
logging.info('BAZARR Restart failed, please restart Bazarr manually')
updated(restart=False)
else: else:
database.execute("UPDATE system SET updated='1'") database.execute("UPDATE system SET updated='1'")

@ -464,38 +464,39 @@ def test_notification(protocol, provider):
return '', 200 return '', 200
class Server(): class Server:
def __init__(self): # Mute DeprecationWarning
# Mute DeprecationWarning warnings.simplefilter("ignore", DeprecationWarning)
warnings.simplefilter("ignore", DeprecationWarning) # Mute Insecure HTTPS requests made to Sonarr and Radarr
# Mute Insecure HTTPS requests made to Sonarr and Radarr warnings.filterwarnings('ignore', message='Unverified HTTPS request')
warnings.filterwarnings('ignore', message='Unverified HTTPS request') # Mute Python3 BrokenPipeError
# Mute Python3 BrokenPipeError warnings.simplefilter("ignore", BrokenPipeError)
warnings.simplefilter("ignore", BrokenPipeError)
if args.dev:
if args.dev: server = app.run(
self.server = app.run( host=str(settings.general.ip),
host=str(settings.general.ip), port=(int(args.port) if args.port else int(settings.general.port)))
port=(int(args.port) if args.port else int(settings.general.port))) else:
else: server = create_server(app,
self.server = create_server(app, host=str(settings.general.ip),
host=str(settings.general.ip), port=int(args.port) if args.port else int(settings.general.port),
port=int(args.port) if args.port else int(settings.general.port), threads=24)
threads=24)
def start(self): @classmethod
def start(cls):
try: try:
logging.info( logging.info(
'BAZARR is started and waiting for request on http://' + str(settings.general.ip) + ':' + (str( '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)) args.port) if args.port else str(settings.general.port)) + str(base_url))
if not args.dev: if not args.dev:
self.server.run() cls.server.run()
except KeyboardInterrupt: except KeyboardInterrupt:
self.shutdown() cls.shutdown()
def shutdown(self): @classmethod
def shutdown(cls):
try: try:
self.server.close() cls.server.close()
except: except:
logging.error('BAZARR Cannot stop Waitress.') logging.error('BAZARR Cannot stop Waitress.')
else: else:
@ -510,9 +511,10 @@ class Server():
stop_file.close() stop_file.close()
os._exit(0) os._exit(0)
def restart(self): @classmethod
def restart(cls):
try: try:
self.server.close() cls.server.close()
except: except:
logging.error('BAZARR Cannot stop Waitress.') logging.error('BAZARR Cannot stop Waitress.')
else: else:
@ -528,8 +530,5 @@ class Server():
os._exit(0) os._exit(0)
webserver = Server()
if __name__ == "__main__": if __name__ == "__main__":
webserver.start() Server.start()

Loading…
Cancel
Save