1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-16 14:54:55 +00:00
calibre-web/cps.py

58 lines
1.9 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
base_path = os.path.dirname(os.path.abspath(__file__))
# Insert local directories into path
sys.path.append(base_path)
sys.path.append(os.path.join(base_path, 'cps'))
sys.path.append(os.path.join(base_path, 'vendor'))
from cps import web
2017-03-19 16:14:16 +00:00
try:
from gevent.wsgi import WSGIServer
gevent_present = True
except ImportError:
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
gevent_present = False
if __name__ == '__main__':
if web.ub.DEVELOPMENT:
2017-04-02 08:05:07 +00:00
web.app.run(port=web.ub.config.config_port, debug=True)
else:
2017-03-19 16:14:16 +00:00
if gevent_present:
2017-03-16 21:02:49 +00:00
web.app.logger.info('Attempting to start gevent')
web.start_gevent()
2017-03-19 16:14:16 +00:00
else:
2017-03-16 21:02:49 +00:00
web.app.logger.info('Falling back to Tornado')
2018-03-30 08:39:53 +00:00
# Max Buffersize set to 200MB
2018-03-30 19:20:47 +00:00
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()}
else:
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 19:20:47 +00:00
if web.helper.global_task == 0:
2017-02-21 18:40:22 +00:00
web.app.logger.info("Performing restart of Calibre-web")
2018-05-27 16:44:06 +00: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)
else:
2017-02-21 18:40:22 +00:00
web.app.logger.info("Performing shutdown of Calibre-web")
sys.exit(0)