bootstrap-network.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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]
  12. # network: a network configuration file
  13. #
  14. # Get a working chutney path
  15. if [ ! -d "$CHUTNEY_PATH" ] || [ ! -x "$CHUTNEY_PATH/chutney" ]; then
  16. # looks like a broken path: use the path to this tool instead
  17. TOOLS_PATH=$(dirname "$0")
  18. CHUTNEY_PATH=$(dirname "$TOOLS_PATH")
  19. export CHUTNEY_PATH
  20. fi
  21. if [ -d "$PWD/$CHUTNEY_PATH" ] && [ -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. CHUTNEY="$CHUTNEY_PATH/chutney"
  26. myname=$(basename "$0")
  27. if [ -z "$1" ]; then
  28. echo "$myname: the network wasn't provided"
  29. exit 1
  30. fi
  31. [ -d "$CHUTNEY_PATH" ] || \
  32. { echo "$myname: missing chutney directory: $CHUTNEY_PATH"; exit 1; }
  33. [ -x "$CHUTNEY" ] || \
  34. { echo "$myname: missing chutney: $CHUTNEY"; exit 1; }
  35. export CHUTNEY_NETWORK="$1"
  36. [ -e "$CHUTNEY_NETWORK" ] || \
  37. { echo "$myname: missing network file: $CHUTNEY_NETWORK"; exit 1; }
  38. "$CHUTNEY" stop "$CHUTNEY_NETWORK"
  39. if ! "$CHUTNEY" supported "$CHUTNEY_NETWORK"; then
  40. echo "%myname: network not supported."
  41. exit 77
  42. fi
  43. echo "$myname: bootstrapping network: $CHUTNEY_NETWORK"
  44. "$CHUTNEY" configure "$CHUTNEY_NETWORK"
  45. "$CHUTNEY" start "$CHUTNEY_NETWORK"
  46. sleep 3
  47. if ! "$CHUTNEY" status "$CHUTNEY_NETWORK"; then
  48. # Try to work out why the start or status command is failing
  49. CHUTNEY_DEBUG=1 "$CHUTNEY" start "$CHUTNEY_NETWORK"
  50. # Wait a little longer, just in case
  51. sleep 6
  52. CHUTNEY_DEBUG=1 "$CHUTNEY" status "$CHUTNEY_NETWORK"
  53. fi