openbmc / jsnbd

Apache License 2.0
5 stars 3 forks source link

doc: alternative prototype web server implementation with compatibility of mainline nbd-client #4

Closed Jamesits closed 1 year ago

Jamesits commented 1 year ago

If you are using the mainline nbd-client, the C reference implementation might not work. Also, it is really inconvenient to modify nbd-client arguments during development. Here is a simple shell script replacement I use at work I'd like to share with you.

Dependencies:

The script:

# start the web server
cd path/to/jsnbd
path/to/websocketd/websocketd --port=8000 --staticdir=web --binary socat - UNIX-LISTEN:/tmp/nbd.sock &
# at this point, visit http://server-ip:8000 and connect the remote file

# connecting to the NBD server
nbd-client -unix /tmp/nbd.sock /dev/nbd0 -persist -readonly -timeout 30

# disconnecting from the NBD server
nbd-client -d /dev/nbd0

# stop the web server
kill %1
rm -f /tmp/nbd.sock

Tested with nbd-client 3.21.