mirror of
https://github.com/janeczku/calibre-web
synced 2025-12-12 11:18:05 +00:00
Started migration of config to app database
This commit is contained in:
58
cps.py
58
cps.py
@@ -1,9 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
from threading import Thread
|
||||
from multiprocessing import Queue
|
||||
import time
|
||||
|
||||
base_path = os.path.dirname(os.path.abspath(__file__))
|
||||
@@ -12,50 +8,22 @@ base_path = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, os.path.join(base_path, 'vendor'))
|
||||
|
||||
from cps import web
|
||||
from cps import config
|
||||
# from cps import config
|
||||
from tornado.wsgi import WSGIContainer
|
||||
from tornado.httpserver import HTTPServer
|
||||
from tornado.ioloop import IOLoop
|
||||
|
||||
global title_sort
|
||||
|
||||
|
||||
def start_calibreweb(messagequeue):
|
||||
web.global_queue = messagequeue
|
||||
if config.DEVELOPMENT:
|
||||
web.app.run(host="0.0.0.0", port=config.PORT, debug=True)
|
||||
else:
|
||||
http_server = HTTPServer(WSGIContainer(web.app))
|
||||
http_server.listen(config.PORT)
|
||||
IOLoop.instance().start()
|
||||
print "Tornado finished"
|
||||
http_server.stop()
|
||||
|
||||
|
||||
def stop_calibreweb():
|
||||
# Close Database connections for user and data
|
||||
web.db.session.close()
|
||||
web.db.engine.dispose()
|
||||
web.ub.session.close()
|
||||
web.ub.engine.dispose()
|
||||
test=IOLoop.instance()
|
||||
test.add_callback(test.stop)
|
||||
print("Asked Tornado to exit")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if config.DEVELOPMENT:
|
||||
web.app.run(host="0.0.0.0",port=config.PORT, debug=True)
|
||||
else:
|
||||
while True:
|
||||
q = Queue()
|
||||
t = Thread(target=start_calibreweb, args=(q,))
|
||||
t.start()
|
||||
while True: #watching queue, if there is no call than sleep, otherwise break
|
||||
if q.empty():
|
||||
time.sleep(1)
|
||||
else:
|
||||
break
|
||||
stop_calibreweb()
|
||||
t.join()
|
||||
'''if config.DEVELOPMENT:
|
||||
web.app.run(host="0.0.0.0", port=web.config.config_port, debug=True)
|
||||
else:'''
|
||||
http_server = HTTPServer(WSGIContainer(web.app))
|
||||
http_server.listen(web.config.config_port)
|
||||
IOLoop.instance().start()
|
||||
|
||||
if web.global_task == 0:
|
||||
print("Performing restart of Calibre-web")
|
||||
os.execl(sys.executable,sys.executable, *sys.argv)
|
||||
else:
|
||||
print("Performing shutdown of Calibre-web")
|
||||
os._exit(0)
|
||||
|
||||
Reference in New Issue
Block a user