2017-01-29 20:06:08 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2015-08-02 18:59:11 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2016-12-23 08:53:39 +00:00
|
|
|
|
2015-08-02 18:59:11 +00:00
|
|
|
base_path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
# Insert local directories into path
|
2017-03-05 09:40:39 +00: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 18:59:11 +00:00
|
|
|
|
|
|
|
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
|
2015-08-02 18:59:11 +00:00
|
|
|
|
2016-12-23 08:53:39 +00:00
|
|
|
if __name__ == '__main__':
|
2017-01-28 19:16:40 +00:00
|
|
|
if web.ub.DEVELOPMENT:
|
2017-04-02 08:05:07 +00:00
|
|
|
web.app.run(port=web.ub.config.config_port, debug=True)
|
2017-01-28 19:16:40 +00:00
|
|
|
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')
|
2017-03-07 22:38:23 +00:00
|
|
|
http_server = HTTPServer(WSGIContainer(web.app))
|
2017-09-12 19:49:38 +00:00
|
|
|
http_server.listen(web.ub.config.config_port)
|
2017-03-07 22:38:23 +00:00
|
|
|
IOLoop.instance().start()
|
2017-03-18 12:48:59 +00:00
|
|
|
IOLoop.instance().close(True)
|
2017-01-22 15:44:37 +00:00
|
|
|
|
2017-02-20 18:52:00 +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")
|
2017-01-28 19:16:40 +00:00
|
|
|
os.execl(sys.executable, sys.executable, *sys.argv)
|
2016-12-23 08:53:39 +00:00
|
|
|
else:
|
2017-02-21 18:40:22 +00:00
|
|
|
web.app.logger.info("Performing shutdown of Calibre-web")
|
2017-01-28 19:16:40 +00:00
|
|
|
sys.exit(0)
|