Skip to content

Instantly share code, notes, and snippets.

@debajyoti-thetaonelab
Last active February 8, 2019 09:11
Show Gist options
  • Select an option

  • Save debajyoti-thetaonelab/886450608daeef58a743321744ac3474 to your computer and use it in GitHub Desktop.

Select an option

Save debajyoti-thetaonelab/886450608daeef58a743321744ac3474 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Create a tmux session each session
tmux new -d -s kyc
# Don't create tunnel if ip is 10.22.150.89
# Find the ip address
h=$(hostname)
h=${h:3:${#h}}
myip=${h//-/.}
eth0ip=10.22.150.89
# if [[ $myip = $eth0ip ]]; then
# echo "master";
# else
# echo "slave"
# # Create postgresql tunnel, and keep it in foreground(? We may also send it to background and notify from node’s api if 5432 becomes unreachable)
# tmux send-keys "ssh -L 5432:localhost:5432 ubuntu@$eth0ip" c-m
# fi
# Create another tmux window
# tmux new-w
# get last created network’s directory
LATEST_NODE=$(ls -td ~/kyc-2/quorum-maker/*/ | head -n 1)
LATEST_NODE_NAME=$(basename $LATEST_NODE)
tmux send-keys "export LATEST_NODE=$LATEST_NODE" c-m
# cd into last created network’s directory, we found in previous command
tmux send-keys "cd \$LATEST_NODE" c-m
# TODO: check for start.sh, if not we haven’t created a network yet or there is some issue
# start the quorum
tmux send-keys ./start.sh c-m
# start tailing geth's output in split window
tmux split
tmux send-keys "tail -f ${LATEST_NODE}node/qdata/gethLogs/$LATEST_NODE_NAME.log" c-m
# start the node server process in new window
tmux new-w
tmux send-keys "cd ~/kyc-2/api" c-m
typeset -A NODE_API_MAP
NODE_API_MAP["10.22.150.89"]="server-user.js"
NODE_API_MAP["10.22.150.151"]="server-validator.js"
NODE_API_MAP["10.22.150.252"]="server-verifier.js"
NODE_API_MAP["10.22.150.111"]="server-admin.js"
NODE_API_MAP["10.22.150.154"]="automated-verification.js"
# Tell nodejs server to connect to 10.22.150.89's pg
if [[ ! $myip = $eth0ip ]]; then
tmux send-keys "export PG_HOST=10.22.150.89" c-m
fi
SCRIPT_NAME=${NODE_API_MAP[$myip]}
tmux send-keys "export NODE_PORT=8080 && while [ : ]; do node $SCRIPT_NAME ; sleep 2 ; done " c-m
# start the node reverse-proxy, proxying to geth in a new window
tmux new-w
tmux send-keys "cd ~/kyc-2/kyc-geth-proxy" c-m
tmux send-keys "while [ : ]; do node . 22000 3000 ; sleep 2 ; done " c-m
tmux new-w
# mount the swap. TODO: put this in fstab
sudo swapon /swapfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment