bootstrap-network.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. #
  3. # 1. potentially stop running network
  4. # 2. bootstrap a network from scratch as quickly as possible
  5. # 3. tail -F all the tor log files
  6. #
  7. # NOTE: leaves debris around by renaming directory net/nodes
  8. # and creating a new net/nodes
  9. #
  10. # Usage:
  11. # tools/bootstrap-network.sh [network-flavour]
  12. # network-flavour: one of the files in the networks directory,
  13. # (default: 'basic')
  14. #
  15. # Get a working chutney path
  16. if [ ! -d "$CHUTNEY_PATH" ] || [ ! -x "$CHUTNEY_PATH/chutney" ]; then
  17. # looks like a broken path: use the path to this tool instead
  18. TOOLS_PATH=$(dirname "$0")
  19. CHUTNEY_PATH=$(dirname "$TOOLS_PATH")
  20. export CHUTNEY_PATH
  21. fi
  22. if [ -d "$PWD/$CHUTNEY_PATH" ] && [ -x "$PWD/$CHUTNEY_PATH/chutney" ]; then
  23. # looks like a relative path: make chutney path absolute
  24. export CHUTNEY_PATH="$PWD/$CHUTNEY_PATH"
  25. fi
  26. # Get a working net path
  27. if [ ! -d "$CHUTNEY_DATA_DIR" ]; then
  28. # looks like a broken path: use the chutney path as a base
  29. export CHUTNEY_DATA_DIR="$CHUTNEY_PATH/net"
  30. fi
  31. if [ -d "$PWD/$CHUTNEY_DATA_DIR" ]; then
  32. # looks like a relative path: make chutney path absolute
  33. export CHUTNEY_DATA_DIR="$PWD/$CHUTNEY_DATA_DIR"
  34. fi
  35. CHUTNEY="$CHUTNEY_PATH/chutney"
  36. myname=$(basename "$0")
  37. [ -d "$CHUTNEY_PATH" ] || \
  38. { echo "$myname: missing chutney directory: $CHUTNEY_PATH"; exit 1; }
  39. [ -x "$CHUTNEY" ] || \
  40. { echo "$myname: missing chutney: $CHUTNEY"; exit 1; }
  41. # Set the variables for the chutney network flavour
  42. export NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs-v2"}
  43. [ -n "$1" ] && { NETWORK_FLAVOUR=$1; shift; }
  44. export CHUTNEY_NETWORK="$CHUTNEY_PATH/networks/$NETWORK_FLAVOUR"
  45. [ -e "$CHUTNEY_NETWORK" ] || \
  46. { echo "$myname: missing network file: $CHUTNEY_NETWORK"; exit 1; }
  47. "$CHUTNEY" stop "$CHUTNEY_NETWORK"
  48. echo "$myname: bootstrapping network: $NETWORK_FLAVOUR"
  49. "$CHUTNEY" configure "$CHUTNEY_NETWORK"
  50. "$CHUTNEY" start "$CHUTNEY_NETWORK"
  51. sleep 3
  52. if ! "$CHUTNEY" status "$CHUTNEY_NETWORK"; then
  53. # Try to work out why the start or status command is failing
  54. CHUTNEY_DEBUG=1 "$CHUTNEY" start "$CHUTNEY_NETWORK"
  55. # Wait a little longer, just in case
  56. sleep 6
  57. CHUTNEY_DEBUG=1 "$CHUTNEY" status "$CHUTNEY_NETWORK"
  58. fi