Skip to content

Instantly share code, notes, and snippets.

@BriCo84
Forked from mesquka/incognito_eth.sh
Last active January 17, 2021 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BriCo84/e3d795f8e0e827eee13508e7c3d1c99e to your computer and use it in GitHub Desktop.
Save BriCo84/e3d795f8e0e827eee13508e7c3d1c99e to your computer and use it in GitHub Desktop.
Run multiple vNodes on the same machine/cloud VM
#!/bin/bash
#***********************************************************************************************************
#
#INSTRUCTIONS FOR SETTING UP YOUR NODE(S)...
#
#Prep a spare PC with ubuntu server 18 or higher installed and copy this script (after adding your keys)
#to a thumb drive (make sure its formatted in fat or fat32). Use notepad to edit the file to add your keys and make sure you keep the double quotes
#
#1. install a copy of ubuntu server on a spare pc (ubuntu server, basic server, no gui, i am using 18LTS, but 20LTS is the latest)
#2. sudo apt-get update
#3. sudo apt-get upgrade
#4. sudo apt install -y docker.io (you can skip this if you want, as the script will install docker, but
# after it does so, it requires a reboot of the server, so this makes things easier)
#5. cd /
#6. sudo fdisk -l (or "lsblk) and note the parition location of your usb drive
#7. sudo mkdir nodes
#8. sudo mkdir /media/usb-drive
#9. sudo mount /dev/sda1 (<--whatever is the usb drive location found with fdisk command above) /media/usb-drive
#10. cd /media/usb-drive
#11. sudo cp incognito_eth.sh /nodes
#12. cd /nodes
#13. sudo umount /media/usb-drive (you can now remove your thumbdrive)
#14. sudo ./incognito_eth.sh
#
#
#***********************************************************************************************************
validator_keys=(
"KEY 1"
"KEY 2"
"KEY 3"
...
"KEY X"
)
#***********************************************************************************************************************************
#If running additional physical machines, modify 0 value to
#neccessary bump to start at a higher port number and node count
#***********************************************************************************************************************************
declare -i iteration_bump
iteration_bump=0
run()
{
bootnode="mainnet-bootnode.incognito.org:9330"
latest_tag=$1
current_tag=$2
#********************************************************************
#NEED TO ADD CODE HERE TO FIRST CHECK IF DOCKER CONTAINER IS THERE BEFORE TRYING TO DELETE
#THIS WILL PREVENT THE ERROR MESSAGE WE ARE SEEING
#**********************************************************************
for i in "${!validator_keys[@]}"
do
declare -i b
b=i+iteration_bump
docker rm -f "inc_mainnet_$b"
done
if [ "$current_tag" != "" ]
then
docker image rm -f incognitochain/incognito-mainnet:${current_tag}
fi
if [ ! -d "$PWD/eth-mainnet-data" ]
then
mkdir $PWD/eth-mainnet-data
chmod -R 777 $PWD/eth-mainnet-data
fi
docker pull incognitochain/incognito-mainnet:${latest_tag}
#*********************************************************************************
#RECEIVING AN ERROR HERE "ERROR RESPONSE FROM DAEMON: NETWORK WITH NAME INC_NET ALREADY EXISTS". MAYBE ITS ONLY ON SUBSEQUENT RUNS? Either way, lets see if there is a check option here to check if it exists before trying to create it
docker network create --driver bridge inc_net || true
#*************************************************************************************
#RECEVIGIN AN ERROR I THINK IS HERE "ERROR RESPONSE FROM DAEMON: CONFLICT. THE CONTAINER NAME "/ETH_MAINENET" IS ALREADY IN USE BY CONTAINER "DFS.....DFSDF". YOU HAVE
#TO REMOVE (OR RENAME) THAT CONTAINER TO BE ABLE TO REUSE THAT NAME."
#
#THIS MAY ONLY SHOW UP ON SUBSEQUENT RUNS, NEED TO CHECK THIS, BUT EITHER WAY SHOULD TRY AND RESOVLE
docker run --restart=always --net inc_net -d --name eth_mainnet -p 8545:8545 -p 30303:30303 -v $PWD/eth-mainnet-data:/geth -it ethereum/client-go --syncmode light --datadir /geth --rpcaddr 0.0.0.0 --rpcport 8545 --rpc --rpccorsdomain "*"
for i in "${!validator_keys[@]}"
do
declare -i b
b=i+iteration_bump
docker run --restart=always -p $((9334 + b)):$((9334 + b)) -p $((9433 + b)):$((9433 + b)) --net inc_net -e NODE_PORT=$((9433 + b)) -e RPC_PORT=$((9334 + b)) -e BOOTNODE_IP=$bootnode -e GETH_NAME=eth_mainnet -e MININGKEY=${validator_keys[$i]} -e TESTNET=false -e LIMIT_FEE=1 -v $PWD/data${i}:/data -itd --name inc_mainnet_${b} incognitochain/incognito-mainnet:${latest_tag}
done
}
if [ -x "$(command -v docker)" ]; then
echo "Docker Already Installed"
else
echo "Installing Docker"
bash -c "wget -qO- https://get.docker.com/ | sh"
sudo usermod -aG docker $USER
echo "PLEASE RESTART YOUR COMPUTER AND RE-RUN THIS SCRIPT"
exit
fi
ps aux | grep 'incognito.sh' | awk '{ print $2}' | grep -v "^$$\$" | xargs kill -9
current_latest_tag=""
while [ 1 = 1 ]
do
tags=`curl -X GET https://registry.hub.docker.com/v1/repositories/incognitochain/incognito-mainnet/tags | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}' | sed -e 's/\n/;/g'`
sorted_tags=($(echo ${tags[*]}| tr " " "\n" | sort -rn))
latest_tag=${sorted_tags[0]}
if [ "$current_latest_tag" != "$latest_tag" ]
then
run $latest_tag $current_latest_tag
current_latest_tag=$latest_tag
fi
for i in "${!validator_keys[@]}"
do
declare -i b
b=i+iteration_bump
docker start "inc_mainnet_$b"
done
sleep 36s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment