-
-
Save raulmarcosl/689bb0ce3c108a6af270990f7c10ff16 to your computer and use it in GitHub Desktop.
Tezos-Node: If Connection To Private Node is Lost, Trust then Connect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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