pull/997/head
Louis Vézina 5 years ago
parent cdf614192e
commit 4074e85b1c

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

@ -9,10 +9,8 @@ os.environ["BAZARR_VERSION"] = bazarr_version
import gc
import sys
import libs
import io
import hashlib
import warnings
import apprise
import requests
import calendar
@ -23,13 +21,10 @@ from logger import empty_log
from config import settings, url_sonarr, url_radarr, url_radarr_short, url_sonarr_short, base_url, configure_proxy_func
from init import *
import logging
from database import database, dict_mapper
from notifier import update_notifier
from waitress.server import create_server
from urllib.parse import unquote
from get_languages import load_language_in_db, language_from_alpha3, language_from_alpha2, alpha2_from_alpha3
from flask import make_response, request, redirect, abort, render_template, Response, session, flash, url_for, \
@ -41,14 +36,9 @@ from get_movies import *
from scheduler import Scheduler
from check_update import check_and_apply_update
from server import app, webserver
from functools import wraps
from app import create_app
app = create_app()
from api import api_bp
app.register_blueprint(api_bp)
scheduler = Scheduler()
# Check and install update on startup when running on Windows from installer
@ -464,71 +454,5 @@ def test_notification(protocol, provider):
return '', 200
class Server:
def __init__(self):
# Mute DeprecationWarning
warnings.simplefilter("ignore", DeprecationWarning)
# Mute Insecure HTTPS requests made to Sonarr and Radarr
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
# Mute Python3 BrokenPipeError
warnings.simplefilter("ignore", BrokenPipeError)
if args.dev:
self.server = app.run(host=str(settings.general.ip),
port=(int(args.port) if args.port else int(settings.general.port)))
else:
self.server = create_server(app,
host=str(settings.general.ip),
port=int(args.port) if args.port else int(settings.general.port),
threads=24)
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:
self.server.run()
except KeyboardInterrupt:
self.shutdown()
def shutdown(self):
try:
self.server.close()
except Exception as e:
logging.error('BAZARR Cannot stop Waitress: ' + repr(e))
else:
database.close()
try:
stop_file = io.open(os.path.join(args.config_dir, "bazarr.stop"), "w", encoding='UTF-8')
except Exception as e:
logging.error('BAZARR Cannot create bazarr.stop file: ' + repr(e))
else:
logging.info('Bazarr is being shutdown...')
stop_file.write(str(''))
stop_file.close()
os._exit(0)
def restart(self):
try:
self.server.close()
except Exception as e:
logging.error('BAZARR Cannot stop Waitress: ' + repr(e))
else:
database.close()
try:
restart_file = io.open(os.path.join(args.config_dir, "bazarr.restart"), "w", encoding='UTF-8')
except Exception as e:
logging.error('BAZARR Cannot create bazarr.restart file: ' + repr(e))
else:
logging.info('Bazarr is being restarted...')
restart_file.write(str(''))
restart_file.close()
os._exit(0)
global webserver
webserver = Server()
if __name__ == "__main__":
webserver.start()

@ -0,0 +1,81 @@
import warnings
import logging
import os
import io
from waitress.server import create_server
from get_args import args
from config import settings, base_url
from database import database
from app import create_app
app = create_app()
from api import api_bp
app.register_blueprint(api_bp)
class Server:
def __init__(self):
# Mute DeprecationWarning
warnings.simplefilter("ignore", DeprecationWarning)
# Mute Insecure HTTPS requests made to Sonarr and Radarr
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
# Mute Python3 BrokenPipeError
warnings.simplefilter("ignore", BrokenPipeError)
if args.dev:
self.server = app.run(host=str(settings.general.ip),
port=(int(args.port) if args.port else int(settings.general.port)))
else:
self.server = create_server(app,
host=str(settings.general.ip),
port=int(args.port) if args.port else int(settings.general.port),
threads=24)
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:
self.server.run()
except KeyboardInterrupt:
self.shutdown()
def shutdown(self):
try:
self.server.close()
except Exception as e:
logging.error('BAZARR Cannot stop Waitress: ' + repr(e))
else:
database.close()
try:
stop_file = io.open(os.path.join(args.config_dir, "bazarr.stop"), "w", encoding='UTF-8')
except Exception as e:
logging.error('BAZARR Cannot create bazarr.stop file: ' + repr(e))
else:
logging.info('Bazarr is being shutdown...')
stop_file.write(str(''))
stop_file.close()
os._exit(0)
def restart(self):
try:
self.server.close()
except Exception as e:
logging.error('BAZARR Cannot stop Waitress: ' + repr(e))
else:
database.close()
try:
restart_file = io.open(os.path.join(args.config_dir, "bazarr.restart"), "w", encoding='UTF-8')
except Exception as e:
logging.error('BAZARR Cannot create bazarr.restart file: ' + repr(e))
else:
logging.info('Bazarr is being restarted...')
restart_file.write(str(''))
restart_file.close()
os._exit(0)
webserver = Server()
Loading…
Cancel
Save