Skip to content

Instantly share code, notes, and snippets.

Last active Dec 18, 2019
What would you like to do?
Tezos-Node: If Connection To Private Node is Lost, Trust then Connect
# Usage ./ 300
# checks twice, 300 seconds in between, if the node the script is being run on
# is connected to 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.
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:
/home/$tezosuser/tezos/tezos-admin-client trust address $privnodeip:9732
/home/$tezosuser/tezos/tezos-admin-client connect address $privnodeip:9732
#echo "Private node has connected in the last $timeallowed seconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment