Skip to content

Commit

Permalink
Problem: Signals do not propagate to child BigchainDB processes (#2395).
Browse files Browse the repository at this point in the history
Solution: Run child processes as daemons to make the signals propagate. Add a short shutdown description to the setup guide.
  • Loading branch information
muawiakh authored and ldmberman committed Jul 26, 2018
1 parent 2386ca9 commit 0c33b4c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bigchaindb/start.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging

import setproctitle

import bigchaindb
Expand Down Expand Up @@ -34,14 +33,14 @@

def start():
# Exchange object for event stream api
logger.info('Starting BigchainDB')
exchange = Exchange()

# start the web api
app_server = server.create_server(
settings=bigchaindb.config['server'],
log_config=bigchaindb.config['log'],
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)
p_webapi.start()

# start message
Expand All @@ -50,16 +49,18 @@ def start():
# start websocket server
p_websocket_server = Process(name='bigchaindb_ws',
target=websocket_server.start,
daemon=True,
args=(exchange.get_subscriber_queue(EventTypes.BLOCK_VALID),))
p_websocket_server.start()

# connect to tendermint event stream
p_websocket_client = Process(name='bigchaindb_ws_to_tendermint',
target=event_stream.start,
daemon=True,
args=(exchange.get_publisher_queue(),))
p_websocket_client.start()

p_exchange = Process(name='bigchaindb_exchange', target=exchange.run)
p_exchange = Process(name='bigchaindb_exchange', target=exchange.run, daemon=True)
p_exchange.start()

# We need to import this after spawning the web server
Expand All @@ -69,6 +70,7 @@ def start():

setproctitle.setproctitle('bigchaindb')

# Start the ABCIServer
app = ABCIServer(app=App())
app.run()

Expand Down
42 changes: 42 additions & 0 deletions docs/server/source/simple-network-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,48 @@ If you want to refresh your node back to a fresh empty state, then your best bet
- reset Tendermint using `tendermint unsafe_reset_all`
- delete the directory `$HOME/.tendermint`

## Shutting down BigchainDB

If you want to stop/kill BigchainDB, you can do so by sending `SIGINT`, `SIGQUIT` or `SIGTERM` to the running BigchainDB
process(es). Depending on how you started BigchainDB i.e. foreground or background. e.g. you started BigchainDB in the background as mentioned above in the guide:

```bash
$ nohup bigchaindb start 2>&1 > bigchaindb.log &

$ # Check the PID of the main BigchainDB process
$ ps -ef | grep bigchaindb
<user> *<pid> <ppid> <C> <STIME> <tty> <time> bigchaindb
<user> <pid> <ppid>* <C> <STIME> <tty> <time> gunicorn: master [bigchaindb_gunicorn]
<user> <pid> <ppid>* <C> <STIME> <tty> <time> bigchaindb_ws
<user> <pid> <ppid>* <C> <STIME> <tty> <time> bigchaindb_ws_to_tendermint
<user> <pid> <ppid>* <C> <STIME> <tty> <time> bigchaindb_exchange
<user> <pid> <ppid> <C> <STIME> <tty> <time> gunicorn: worker [bigchaindb_gunicorn]
<user> <pid> <ppid> <C> <STIME> <tty> <time> gunicorn: worker [bigchaindb_gunicorn]
<user> <pid> <ppid> <C> <STIME> <tty> <time> gunicorn: worker [bigchaindb_gunicorn]
<user> <pid> <ppid> <C> <STIME> <tty> <time> gunicorn: worker [bigchaindb_gunicorn]
<user> <pid> <ppid> <C> <STIME> <tty> <time> gunicorn: worker [bigchaindb_gunicorn]
...

$ # Send any of the above mentioned signals to the parent/root process(marked with `*` for clarity)
# Sending SIGINT
$ kill -2 <bigchaindb_parent_pid>

$ # OR

# Sending SIGTERM
$ kill -15 <bigchaindb_parent_pid>

$ # OR

# Sending SIGQUIT
$ kill -3 <bigchaindb_parent_pid>

# If you want to kill all the processes by name yourself
$ pgrep bigchaindb | xargs kill -9
```

If you started BigchainDB in the foreground, a `Ctrl + C` or `Ctrl + Z` would shut down BigchainDB.

## Member: Dynamically Add a New Member to the Network

TBD.
Expand Down

0 comments on commit 0c33b4c

Please sign in to comment.