You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.8 KiB

  1. #!/usr/bin/env bash
  2. # XXX: this script is intended to be run from a fresh Digital Ocean droplet
  3. # NOTE: you must set this manually now
  4. echo "export DO_API_TOKEN=\"yourToken\"" >> ~/.profile
  5. sudo apt-get update -y
  6. sudo apt-get upgrade -y
  7. sudo apt-get install -y jq unzip python-pip software-properties-common make
  8. # get and unpack golang
  9. curl -O https://storage.googleapis.com/golang/go1.10.linux-amd64.tar.gz
  10. tar -xvf go1.10.linux-amd64.tar.gz
  11. ## move binary and add to path
  12. mv go /usr/local
  13. echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.profile
  14. ## create the goApps directory, set GOPATH, and put it on PATH
  15. mkdir goApps
  16. echo "export GOPATH=/root/goApps" >> ~/.profile
  17. echo "export PATH=\$PATH:\$GOPATH/bin" >> ~/.profile
  18. source ~/.profile
  19. ## get the code and move into repo
  20. REPO=github.com/tendermint/tendermint
  21. go get $REPO
  22. cd $GOPATH/src/$REPO
  23. ## build
  24. git checkout zach/ansible
  25. make get_tools
  26. make get_vendor_deps
  27. make build
  28. # generate an ssh key
  29. ssh-keygen -f $HOME/.ssh/id_rsa -t rsa -N ''
  30. echo "export SSH_KEY_FILE=\"\$HOME/.ssh/id_rsa.pub\"" >> ~/.profile
  31. source ~/.profile
  32. # install terraform
  33. wget https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip
  34. unzip terraform_0.11.7_linux_amd64.zip -d /usr/bin/
  35. # install ansible
  36. sudo apt-get update -y
  37. sudo apt-add-repository ppa:ansible/ansible -y
  38. sudo apt-get update -y
  39. sudo apt-get install ansible -y
  40. # required by ansible
  41. pip install dopy
  42. # the next two commands are directory sensitive
  43. cd $GOPATH/src/github.com/tendermint/tendermint/networks/remote/terraform
  44. terraform init
  45. terraform apply -var DO_API_TOKEN="$DO_API_TOKEN" -var SSH_KEY_FILE="$SSH_KEY_FILE" -auto-approve
  46. # let the droplets boot
  47. sleep 60
  48. # get the IPs
  49. ip0=`terraform output -json public_ips | jq '.value[0]'`
  50. ip1=`terraform output -json public_ips | jq '.value[1]'`
  51. ip2=`terraform output -json public_ips | jq '.value[2]'`
  52. ip3=`terraform output -json public_ips | jq '.value[3]'`
  53. # to remove quotes
  54. strip() {
  55. opt=$1
  56. temp="${opt%\"}"
  57. temp="${temp#\"}"
  58. echo $temp
  59. }
  60. ip0=$(strip $ip0)
  61. ip1=$(strip $ip1)
  62. ip2=$(strip $ip2)
  63. ip3=$(strip $ip3)
  64. # all the ansible commands are also directory specific
  65. cd $GOPATH/src/github.com/tendermint/tendermint/networks/remote/ansible
  66. ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  67. ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$GOPATH/src/github.com/tendermint/tendermint/build/tendermint -e CONFIGDIR=$GOPATH/src/github.com/tendermint/tendermint/docs/examples
  68. sleep 10
  69. # get each nodes ID then populate the ansible file
  70. id0=`curl $ip0:46657/status | jq .result.node_info.id`
  71. id1=`curl $ip1:46657/status | jq .result.node_info.id`
  72. id2=`curl $ip2:46657/status | jq .result.node_info.id`
  73. id3=`curl $ip3:46657/status | jq .result.node_info.id`
  74. id0=$(strip $id0)
  75. id1=$(strip $id1)
  76. id2=$(strip $id2)
  77. id3=$(strip $id3)
  78. # remove file we'll re-write to with new info
  79. old_ansible_file=$GOPATH/src/github.com/tendermint/tendermint/networks/remote/ansible/roles/install/templates/systemd.service.j2
  80. rm $old_ansible_file
  81. # need to populate the `--p2p.persistent_peers` flag
  82. echo "[Unit]
  83. Description={{service}}
  84. Requires=network-online.target
  85. After=network-online.target
  86. [Service]
  87. Restart=on-failure
  88. User={{service}}
  89. Group={{service}}
  90. PermissionsStartOnly=true
  91. ExecStart=/usr/bin/tendermint node --proxy_app=kvstore --p2p.persistent_peers=$id0@$ip0:46656,$id1@$ip1:46656,$id2@$ip2:46656,$id3@$ip3:46656
  92. ExecReload=/bin/kill -HUP \$MAINPID
  93. KillSignal=SIGTERM
  94. [Install]
  95. WantedBy=multi-user.target
  96. " >> $old_ansible_file
  97. # now, we can re-run the install command
  98. ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  99. # and finally restart it all
  100. ansible-playbook -i inventory/digital_ocean.py -l sentrynet restart.yml
  101. echo "congratulations, your testnet is now running :)"