Reconnecting Peers Periodically
Reconnecting Periodically | Medium Article
Peers have a tendency to disconnect from each other if not reconnected manually periodically, so to combat this, you may add the following two files to periodically reconnect to your swarm peers.
sudo su -
cat <<EOF > /lib/systemd/system/gateway-connector.service
[Unit]
Description=Job that periodically connects this IPFS node to the gateway node
[Service]
ExecStart=/usr/local/bin/ipfs swarm connect <ADD_MULTIPLE_CONNECTIONS_HERE_SPACE_SEPARATED> # /ip4/52.70.167.190/tcp/4001/ipfs/QmZ5gLTZwvfD5DkbbaFFX4YJCi7f4C5oQAgq8qpjL8S1ur /ip4/34.224.152.33/tcp/4001/ipfs/QmcCX4b3EF3eXaDe5dgxTL9mXbyci4FwcJAjWqpub5vCXM
Environment="IPFS_PATH=/root/.ipfs"
EOF
exitsudo su -
cat <<EOF > /lib/systemd/system/gateway-connector.timer
[Unit]
Description=Timer that periodically triggers gateway-connector.service
[Timer]
OnBootSec=3min
OnUnitActiveSec=1min
[Install]
WantedBy=timers.target
EOF
exitNow you can enable and start the service:
sudo systemctl enable gateway-connector.timer
sudo systemctl start gateway-connector.timerTo double checked this worked, run:
systemctl list-timersYou should see an entry for your gateway connector service. You can also check the status of its last execution attempt by running:
systemctl status gateway-connectorFinally you can monitor the process with:
journalctl -f | grep ipfsLast updated
Was this helpful?