implement quit api. indicate if backend is offline
This commit is contained in:
parent
67ad0a82e9
commit
5d4ed8ffbc
8 changed files with 83 additions and 35 deletions
|
|
@ -54,12 +54,43 @@ def log_request(handler):
|
|||
log_method("%d %s %.2fms", handler.get_status(),
|
||||
handler._request_summary(), request_time)
|
||||
|
||||
def shutdown():
|
||||
if state.tor:
|
||||
state.tor._shutdown = True
|
||||
if state.downloads:
|
||||
logger.debug('shutdown downloads')
|
||||
state.downloads.join()
|
||||
if state.scraping:
|
||||
logger.debug('shutdown scraping')
|
||||
state.scraping.join()
|
||||
logger.debug('shutdown http_server')
|
||||
state.http_server.stop()
|
||||
if state.tasks:
|
||||
logger.debug('shutdown tasks')
|
||||
state.tasks.join()
|
||||
if state.nodes:
|
||||
logger.debug('shutdown nodes')
|
||||
state.nodes.join()
|
||||
if state.node:
|
||||
state.node.stop()
|
||||
if state.tor:
|
||||
logger.debug('shutdown tor')
|
||||
state.tor.shutdown()
|
||||
if state.PID and os.path.exists(state.PID):
|
||||
logger.debug('remove %s', state.PID)
|
||||
os.unlink(state.PID)
|
||||
|
||||
def run():
|
||||
setup.create_db()
|
||||
PID = sys.argv[2] if len(sys.argv) > 2 else None
|
||||
if len(sys.argv) > 3 and sys.argv[2] == 'debug':
|
||||
PID = sys.argv[3]
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
|
||||
log_format='%(asctime)s:%(levelname)s:%(name)s:%(message)s'
|
||||
if not PID:
|
||||
if debug:
|
||||
logging.basicConfig(level=logging.DEBUG, format=log_format)
|
||||
else:
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
|
|
@ -102,6 +133,8 @@ def run():
|
|||
with open(PID, 'w') as pid:
|
||||
pid.write('%s' % os.getpid())
|
||||
|
||||
state.PID = PID
|
||||
state.http_server = http_server
|
||||
state.main = IOLoop.instance()
|
||||
state.cache = Cache(ttl=60)
|
||||
state.tasks = tasks.Tasks()
|
||||
|
|
@ -134,32 +167,6 @@ def run():
|
|||
print('open browser at %s' % url)
|
||||
logger.debug('Starting OML %s at %s', settings.VERSION, url)
|
||||
|
||||
def shutdown():
|
||||
if state.tor:
|
||||
state.tor._shutdown = True
|
||||
if state.downloads:
|
||||
logger.debug('shutdown downloads')
|
||||
state.downloads.join()
|
||||
if state.scraping:
|
||||
logger.debug('shutdown scraping')
|
||||
state.scraping.join()
|
||||
logger.debug('shutdown http_server')
|
||||
http_server.stop()
|
||||
if state.tasks:
|
||||
logger.debug('shutdown tasks')
|
||||
state.tasks.join()
|
||||
if state.nodes:
|
||||
logger.debug('shutdown nodes')
|
||||
state.nodes.join()
|
||||
if state.node:
|
||||
state.node.stop()
|
||||
if state.tor:
|
||||
logger.debug('shutdown tor')
|
||||
state.tor.shutdown()
|
||||
if PID and os.path.exists(PID):
|
||||
logger.debug('remove %s', PID)
|
||||
os.unlink(PID)
|
||||
|
||||
signal.signal(signal.SIGTERM, shutdown)
|
||||
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue