2017-01-29 12:06:08 -08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2015-08-02 11:59:11 -07:00
|
|
|
import os
|
|
|
|
import sys
|
2016-12-23 00:53:39 -08:00
|
|
|
|
2015-08-02 11:59:11 -07:00
|
|
|
base_path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
# Insert local directories into path
|
2017-03-05 01:40:39 -08:00
|
|
|
sys.path.append(base_path)
|
|
|
|
sys.path.append(os.path.join(base_path, 'cps'))
|
|
|
|
sys.path.append(os.path.join(base_path, 'vendor'))
|
2015-08-02 11:59:11 -07:00
|
|
|
|
|
|
|
from cps import web
|
2017-03-19 09:14:16 -07:00
|
|
|
try:
|
2018-07-07 02:41:39 -07:00
|
|
|
from gevent.pywsgi import WSGIServer
|
2017-03-19 09:14:16 -07:00
|
|
|
gevent_present = True
|
|
|
|
except ImportError:
|
|
|
|
from tornado.wsgi import WSGIContainer
|
|
|
|
from tornado.httpserver import HTTPServer
|
|
|
|
from tornado.ioloop import IOLoop
|
|
|
|
gevent_present = False
|
2015-08-02 11:59:11 -07:00
|
|
|
|
2016-12-23 00:53:39 -08:00
|
|
|
if __name__ == '__main__':
|
2018-06-02 01:59:34 -07:00
|
|
|
if gevent_present:
|
|
|
|
web.app.logger.info('Attempting to start gevent')
|
|
|
|
web.start_gevent()
|
2017-01-28 11:16:40 -08:00
|
|
|
else:
|
2018-06-02 01:59:34 -07:00
|
|
|
web.app.logger.info('Starting Tornado webserver')
|
|
|
|
# Max Buffersize set to 200MB
|
|
|
|
if web.ub.config.get_config_certfile() and web.ub.config.get_config_keyfile():
|
|
|
|
ssl={"certfile": web.ub.config.get_config_certfile(),
|
|
|
|
"keyfile": web.ub.config.get_config_keyfile()}
|
2017-03-19 09:14:16 -07:00
|
|
|
else:
|
2018-06-02 01:59:34 -07:00
|
|
|
ssl=None
|
|
|
|
http_server = HTTPServer(WSGIContainer(web.app),
|
|
|
|
max_buffer_size = 209700000,
|
|
|
|
ssl_options=ssl)
|
|
|
|
http_server.listen(web.ub.config.config_port)
|
|
|
|
IOLoop.instance().start()
|
|
|
|
IOLoop.instance().close(True)
|
2018-03-30 12:20:47 -07:00
|
|
|
|
2017-02-20 10:52:00 -08:00
|
|
|
if web.helper.global_task == 0:
|
2017-02-21 10:40:22 -08:00
|
|
|
web.app.logger.info("Performing restart of Calibre-web")
|
2018-05-27 09:44:06 -07:00
|
|
|
if os.name == 'nt':
|
|
|
|
arguments = ["\"" + sys.executable + "\""]
|
|
|
|
for e in sys.argv:
|
|
|
|
arguments.append("\"" + e + "\"")
|
|
|
|
os.execv(sys.executable, arguments)
|
|
|
|
else:
|
|
|
|
os.execl(sys.executable, sys.executable, *sys.argv)
|
2016-12-23 00:53:39 -08:00
|
|
|
else:
|
2017-02-21 10:40:22 -08:00
|
|
|
web.app.logger.info("Performing shutdown of Calibre-web")
|
2017-01-28 11:16:40 -08:00
|
|
|
sys.exit(0)
|