mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: BigchainDB main/parent process does not handle signals
This commit is contained in:
parent
abc6db7999
commit
7c9155257d
@ -1,8 +1,11 @@
|
|||||||
|
import bigchaindb
|
||||||
|
|
||||||
|
import gevent
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import setproctitle
|
import setproctitle
|
||||||
|
import signal
|
||||||
|
|
||||||
import bigchaindb
|
|
||||||
from bigchaindb.tendermint.lib import BigchainDB
|
from bigchaindb.tendermint.lib import BigchainDB
|
||||||
from bigchaindb.tendermint.core import App
|
from bigchaindb.tendermint.core import App
|
||||||
from bigchaindb.web import server, websocket_server
|
from bigchaindb.web import server, websocket_server
|
||||||
@ -31,17 +34,27 @@ BANNER = """
|
|||||||
****************************************************************************
|
****************************************************************************
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
PROCESSES = []
|
||||||
|
|
||||||
|
|
||||||
|
def sig_handler(server):
|
||||||
|
logger.info('Shutting down BigchainDB. Goodbye!')
|
||||||
|
server.stop()
|
||||||
|
for p in PROCESSES:
|
||||||
|
p.terminate()
|
||||||
|
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
# Exchange object for event stream api
|
# Exchange object for event stream api
|
||||||
|
logger.info('Starting BigchainDB')
|
||||||
exchange = Exchange()
|
exchange = Exchange()
|
||||||
|
|
||||||
# start the web api
|
# start the web api
|
||||||
app_server = server.create_server(
|
app_server = server.create_server(
|
||||||
settings=bigchaindb.config['server'],
|
settings=bigchaindb.config['server'],
|
||||||
log_config=bigchaindb.config['log'],
|
log_config=bigchaindb.config['log'],
|
||||||
bigchaindb_factory=BigchainDB)
|
bigchaindb_factory=BigchainDB)
|
||||||
p_webapi = Process(name='bigchaindb_webapi', target=app_server.run)
|
p_webapi = Process(name='bigchaindb_webapi', target=app_server.run, daemon=True)
|
||||||
|
PROCESSES.append(p_webapi)
|
||||||
p_webapi.start()
|
p_webapi.start()
|
||||||
|
|
||||||
# start message
|
# start message
|
||||||
@ -50,16 +63,21 @@ def start():
|
|||||||
# start websocket server
|
# start websocket server
|
||||||
p_websocket_server = Process(name='bigchaindb_ws',
|
p_websocket_server = Process(name='bigchaindb_ws',
|
||||||
target=websocket_server.start,
|
target=websocket_server.start,
|
||||||
|
daemon=True,
|
||||||
args=(exchange.get_subscriber_queue(EventTypes.BLOCK_VALID),))
|
args=(exchange.get_subscriber_queue(EventTypes.BLOCK_VALID),))
|
||||||
|
PROCESSES.append(p_websocket_server)
|
||||||
p_websocket_server.start()
|
p_websocket_server.start()
|
||||||
|
|
||||||
# connect to tendermint event stream
|
# connect to tendermint event stream
|
||||||
p_websocket_client = Process(name='bigchaindb_ws_to_tendermint',
|
p_websocket_client = Process(name='bigchaindb_ws_to_tendermint',
|
||||||
target=event_stream.start,
|
target=event_stream.start,
|
||||||
|
daemon=True,
|
||||||
args=(exchange.get_publisher_queue(),))
|
args=(exchange.get_publisher_queue(),))
|
||||||
|
PROCESSES.append(p_websocket_client)
|
||||||
p_websocket_client.start()
|
p_websocket_client.start()
|
||||||
|
|
||||||
p_exchange = Process(name='bigchaindb_exchange', target=exchange.run)
|
p_exchange = Process(name='bigchaindb_exchange', target=exchange.run, daemon=True)
|
||||||
|
PROCESSES.append(p_exchange)
|
||||||
p_exchange.start()
|
p_exchange.start()
|
||||||
|
|
||||||
# We need to import this after spawning the web server
|
# We need to import this after spawning the web server
|
||||||
@ -69,8 +87,17 @@ def start():
|
|||||||
|
|
||||||
setproctitle.setproctitle('bigchaindb')
|
setproctitle.setproctitle('bigchaindb')
|
||||||
|
|
||||||
|
# Start the ABCIServer and watch for signals to stop
|
||||||
|
# the server and the relevant child processes.
|
||||||
app = ABCIServer(app=App())
|
app = ABCIServer(app=App())
|
||||||
app.run()
|
gevent.signal(signal.SIGTERM, sig_handler, app.server)
|
||||||
|
gevent.signal(signal.SIGQUIT, sig_handler, app.server)
|
||||||
|
gevent.signal(signal.SIGINT, sig_handler, app.server)
|
||||||
|
|
||||||
|
app.server.serve_forever()
|
||||||
|
|
||||||
|
for p in PROCESSES:
|
||||||
|
p.join()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user