VM cluster setup scripts.

This commit is contained in:
ravinsp
2019-11-26 16:31:21 +05:30
parent 0dde10c306
commit f42bd56cb3
5 changed files with 152 additions and 0 deletions

1
test/vm-cluster/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
cfg

View File

@@ -0,0 +1,88 @@
#!/bin/bash
vmpass=""
#ip locations: aueast aueast uswest uswest seasia
vmips=(ip list)
mode=$1
if [ "$mode" = "new" ] || [ "$mode" = "run" ] || [ "$mode" = "update" ]; then
echo ""
else
echo "Invalid command. new | run | update expected."
exit
fi
if [ $mode = "run" ]; then
let n=$2-1
vmip=${vmips[$n]}
sshpass -p $vmpass ssh geveo@$vmip './hpcore run contract'
exit
fi
hpcore=$(realpath ../..)
vmcount=${#vmips[@]}
#vmcount=2
mkdir ./cfg > /dev/null 2>&1
for (( i=0; i<$vmcount; i++ ))
do
vmip=${vmips[i]}
let n=$i+1
#if [ $mode = "update" ]; then
# /bin/bash ./setup-vm.sh $mode $n $vmpass $vmip $hpcore &
#else
/bin/bash ./setup-vm.sh $mode $n $vmpass $vmip $hpcore
#fi
# Collect each node's pub key and peer address.
pubkeys[i]=$(node -p "require('./cfg/node$n.json').pubkeyhex")
peers[i]="$vmip:22860"
done
if [ $mode = "update" ]; then
exit
fi
# Function to generate JSON array string while skiping a given index.
function joinarr {
arrname=$1[@]
arr=("${!arrname}")
skip=$2
j=0
str="["
for (( i=0; i<$vmcount; i++ ))
do
let prevlast=$vmcount-2
if [ "$i" != "$skip" ]
then
str="$str'${arr[i]}'"
if [ $j -lt $prevlast ]
then
str="$str,"
fi
let j=j+1
fi
done
str="$str]"
echo $str
}
# Loop through all nodes hp.cfg and inject peer and unl lists (skip self node).
for (( j=0; j<$vmcount; j++ ))
do
let n=$j+1
mypeers=$(joinarr peers $j)
myunl=$(joinarr pubkeys $j)
node -p "JSON.stringify({...require('./cfg/node$n.json'),binary:'/usr/bin/node',binargs:'/home/geveo/contract.js',peers:${mypeers},unl:${myunl}}, null, 2)" > ./cfg/node$n.cfg
# Copy local cfg file back to remote vm.
vmip=${vmips[j]}
sshpass -p $vmpass scp ./cfg/node$n.cfg geveo@$vmip:~/contract/cfg/hp.cfg
done
rm -r ./cfg

26
test/vm-cluster/setup-hp.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
if [ -x "$(command -v node)" ]; then
echo "NodeJs is installed."
else
echo "Installing NodeJs..."
sudo apt-get update
sudo apt-get -y install curl
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install -y nodejs
# FUSE
sudo cp ./libfuse3.so.3 /usr/local/lib/
sudo ldconfig
# Install fuse.
sudo apt-get update && apt-get install -y fuse && rm -rf /var/lib/apt/lists/*
fi
if [ ! -d "./contract" ]; then
./hpcore new ./contract
pushd ./contract/cfg
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout tlskey.pem -out tlscert.pem \
-subj "/C=AU/ST=ST/L=L/O=O/OU=OU/CN=localhost/emailAddress=hp@example" > /dev/null 2>&1
popd
fi

25
test/vm-cluster/setup-vm.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
mode=$1
nodeid=$2
vmpass=$3
vmip=$4
hpcore=$5
echo $nodeid. $vmip
sshpass -p $vmpass scp $hpcore/build/hpcore \
$hpcore/build/hpstatemon \
$hpcore/libfuse3.so.3 \
$hpcore/examples/echocontract/contract.js \
./setup-hp.sh \
geveo@$vmip:~/
if [ $mode = "new" ]; then
sshpass -p $vmpass ssh geveo@$vmip 'rm -r ~/contract && chmod 700 ~/setup-hp.sh && ~/setup-hp.sh'
else
exit
fi
sshpass -p $vmpass scp geveo@$vmip:~/contract/cfg/hp.cfg ./cfg/node$nodeid.json

View File

@@ -0,0 +1,12 @@
#!/bin/bash
#ac login
#az account list
#az account set --subscription ''
name=$1
loc=$2
vmpass=""
az vm create --name $name --resource-group HotPocket-ResGroup --size Standard_B1s --admin-username geveo --admin-password $vmpass --image UbuntuLTS --location $loc --generate-ssh-keys
az vm open-port --resource-group HotPocket-ResGroup --name $name --port 22860 --priority 900 && \
az vm open-port --resource-group HotPocket-ResGroup --name $name --port 8080 --priority 901