Skip to content

Instantly share code, notes, and snippets.

@gaia

gaia/privconnect.sh

Last active Dec 18, 2019
Embed
What would you like to do?
Tezos-Node: If Connection To Private Node is Lost, Trust then Connect
#!/bin/bash
# Usage ./privconnect.sh 300 1.1.1.1
# checks twice, 300 seconds in between, if the node the script is being run on
# is connected to 1.1.1.1:9732. If it isn't trust then connect.
# Run it from cron, make sure the cron interval is greater than the sleep period
# between connection checks in this script. 2x or 3x the sleep period is good.
timeallowed=$1
privnodeip=$2
tezosuser="tezos"
privnodestatus1=$(netstat -ant | grep :9732 | grep "$privnodeip" | wc -l)
sleep $timeallowed
privnodestatus2=$(netstat -ant | grep :9732 | grep "$privnodeip" | wc -l)
if [ "$privnodestatus1" -eq 0 ] && [ "$privnodestatus2" -eq 0 ];then
echo "$(date): Private node has not connected in the last $timeallowed seconds. Reconnecting..."
#systemctl restart tezos-node
# both trust and connect are needed:
# https://gitlab.com/tezos/tezos/issues/547#note_202870810
/home/$tezosuser/tezos/tezos-admin-client trust address $privnodeip:9732
/home/$tezosuser/tezos/tezos-admin-client connect address $privnodeip:9732
else
#echo "Private node has connected in the last $timeallowed seconds"
:
fi
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.