bootstrap-network.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. flavour=basic; [ -n "$1" ] && { flavour=$1; shift; }
  41. export CHUTNEY_NETWORK="$CHUTNEY_PATH/networks/$NETWORK_FLAVOUR"
  42. [ -e "$CHUTNEY_NETWORK" ] || \
  43. { echo "$myname: missing network file: $CHUTNEY_NETWORK"; exit 1; }
  44. "$CHUTNEY" stop "$CHUTNEY_NETWORK"
  45. echo "$myname: bootstrapping network: $flavour"
  46. "$CHUTNEY" configure "$CHUTNEY_NETWORK"
  47. "$CHUTNEY" start "$CHUTNEY_NETWORK"
  48. sleep 1
  49. if ! "$CHUTNEY" status "$CHUTNEY_NETWORK"; then
  50. # Try to work out why the start or status command is failing
  51. CHUTNEY_DEBUG=1 "$CHUTNEY" start "$CHUTNEY_NETWORK"
  52. # Wait a little longer, just in case
  53. sleep 5
  54. CHUTNEY_DEBUG=1 "$CHUTNEY" status "$CHUTNEY_NETWORK"
  55. fi