Skip to content

Instantly share code, notes, and snippets.

@mesquka

mesquka/incognito_eth.sh

Last active Oct 7, 2020
Embed
What would you like to do?
Run multiple vNodes on the same machine/cloud VM
#!/bin/bash
validator_keys=(
"KEY 1"
"KEY 2"
"KEY 3"
...
"KEY X"
)
run()
{
bootnode="mainnet-bootnode.incognito.org:9330"
latest_tag=$1
current_tag=$2
for i in "${!validator_keys[@]}"
do
docker rm -f "inc_mainnet_$i"
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}
docker network create --driver bridge inc_net || true
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
docker run --restart=always -p $((9334 + $i)):$((9334 + $i)) -p $((9433 + $i)):$((9433 + $i)) --net inc_net -e NODE_PORT=$((9433 + $i)) -e RPC_PORT=$((9334 + $i)) -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_${i} incognitochain/incognito-mainnet:${latest_tag}
done
}
if [ -x "$(command -v docker)" ]; then
echo "Docker 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
docker start "inc_mainnet_$i"
done
sleep 3600s
done
#!/bin/bash
validator_keys=(
"KEY 1"
"KEY 2"
"KEY 3"
...
"KEY X"
)
run()
{
bootnode="mainnet-bootnode.incognito.org:9330"
latest_tag=$1
current_tag=$2
for i in "${!validator_keys[@]}"
do
docker rm -f "inc_mainnet_$i"
done
if [ "$current_tag" != "" ]
then
docker image rm -f incognitochain/incognito-mainnet:${current_tag}
fi
docker pull incognitochain/incognito-mainnet:${latest_tag}
for i in "${!validator_keys[@]}"
do
docker run --restart=always -p $((9334 + $i)):$((9334 + $i)) -p $((9433 + $i)):$((9433 + $i)) -e NODE_PORT=$((9433 + $i)) -e RPC_PORT=$((9334 + $i)) -e BOOTNODE_IP=$bootnode -e MININGKEY=${validator_keys[$i]} -e TESTNET=false -e LIMIT_FEE=1 -v $PWD/data${i}:/data -itd --name inc_mainnet_${i} incognitochain/incognito-mainnet:${latest_tag}
done
}
if [ -x "$(command -v docker)" ]; then
echo "Docker 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
docker start "inc_mainnet_$i"
done
sleep 3600s
done
@zes333

This comment has been minimized.

Copy link

@zes333 zes333 commented Jul 2, 2020

@mesquka
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.