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.
1
sudo su -
2
cat <<EOF > /lib/systemd/system/gateway-connector.service
3
[Unit]
4
Description=Job that periodically connects this IPFS node to the gateway node
5
[Service]
6
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
7
Environment="IPFS_PATH=/root/.ipfs"
8
EOF
9
exit
Copied!
1
sudo su -
2
cat <<EOF > /lib/systemd/system/gateway-connector.timer
3
[Unit]
4
Description=Timer that periodically triggers gateway-connector.service
5
[Timer]
6
OnBootSec=3min
7
OnUnitActiveSec=1min
8
[Install]
9
WantedBy=timers.target
10
EOF
11
exit
Copied!
Now you can enable and start the service:
1
sudo systemctl enable gateway-connector.timer
2
sudo systemctl start gateway-connector.timer
Copied!
To double checked this worked, run:
1
systemctl list-timers
Copied!
You should see an entry for your gateway connector service. You can also check the status of its last execution attempt by running:
1
systemctl status gateway-connector
Copied!
Finally you can monitor the process with:
1
journalctl -f | grep ipfs
Copied!
Copy link