bootstrap-network.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
  17. # looks like a broken path: use the path to this tool instead
  18. TOOLS_PATH=`dirname "$0"`
  19. export CHUTNEY_PATH=`dirname "$TOOLS_PATH"`
  20. fi
  21. if [ -d "$PWD/$CHUTNEY_PATH" -a -x "$PWD/$CHUTNEY_PATH/chutney" ]; then
  22. # looks like a relative path: make chutney path absolute
  23. export CHUTNEY_PATH="$PWD/$CHUTNEY_PATH"
  24. fi
  25. # Get a working net path
  26. if [ ! -d "$CHUTNEY_DATA_DIR" ]; then
  27. # looks like a broken path: use the chutney path as a base
  28. export CHUTNEY_DATA_DIR="$CHUTNEY_PATH/net"
  29. fi
  30. if [ -d "$PWD/$CHUTNEY_DATA_DIR" ]; then
  31. # looks like a relative path: make chutney path absolute
  32. export CHUTNEY_DATA_DIR="$PWD/$CHUTNEY_DATA_DIR"
  33. fi
  34. CHUTNEY="$CHUTNEY_PATH/chutney"
  35. myname=$(basename "$0")
  36. [ -d "$CHUTNEY_PATH" ] || \
  37. { echo "$myname: missing chutney directory: $CHUTNEY_PATH"; exit 1; }
  38. [ -x "$CHUTNEY" ] || \
  39. { echo "$myname: missing chutney: $CHUTNEY"; exit 1; }
  40. # Set the variables for the chutney network flavour
  41. export NETWORK_FLAVOUR=${NETWORK_FLAVOUR:-"bridges+hs-v2"}
  42. [ -n "$1" ] && { NETWORK_FLAVOUR=$1; shift; }
  43. export CHUTNEY_NETWORK="$CHUTNEY_PATH/networks/$NETWORK_FLAVOUR"
  44. [ -e "$CHUTNEY_NETWORK" ] || \
  45. { echo "$myname: missing network file: $CHUTNEY_NETWORK"; exit 1; }
  46. "$CHUTNEY" stop "$CHUTNEY_NETWORK"
  47. echo "$myname: bootstrapping network: $NETWORK_FLAVOUR"
  48. "$CHUTNEY" configure "$CHUTNEY_NETWORK"
  49. "$CHUTNEY" start "$CHUTNEY_NETWORK"
  50. sleep 3
  51. if ! "$CHUTNEY" status "$CHUTNEY_NETWORK"; then
  52. # Try to work out why the start or status command is failing
  53. CHUTNEY_DEBUG=1 "$CHUTNEY" start "$CHUTNEY_NETWORK"
  54. # Wait a little longer, just in case
  55. sleep 6
  56. CHUTNEY_DEBUG=1 "$CHUTNEY" status "$CHUTNEY_NETWORK"
  57. fi