Syncthing Server

From Unixcat.net Wiki
Revision as of 19:36, 12 September 2020 by ToroidalCore (talk | contribs)
Jump to navigation Jump to search

Syncthing is a tool written in Go to keep files synchronised between computers. It's decentralized, meaning instead of syncing to a server, your computers can find each other on the network and sync amongst themselves. While I don't use it outside of my home network, it can run over the internet as well - it uses relay and discovery severs, and can even traverse NAT.

Prior to Syncthing, I used NextCloud, which runs on a web server. I used this to keep some directories on several computers in my home network synchronized. It worked, and I actually still have an install I point my phone too (although Syncthing has an Android app as well). However, sometimes it would be slow, particularly with a lot of small files. The server also stores all of its files in its own directory, and depends on a database (I have used both MariaDB and SQLite), as opposed to Syncthing which is just its own executable.

One advantage of the central model NextCloud uses is that if you only have one of the computers you're syncing online, it can still keep the copy of the server up to date. While Syncthing can deal with conflicts (by renaming the conflicting files), it's nice to not have to have both machines on for them to sync in all cases. (Although again, Syncthing can sync the two if only the two of them are online; NextCloud would still need to talk to its server.) I had already had a machine running with an external hard drive as kind of a stopgap NAS, so I looked into how to get Syncthing going on this as well.

Syncthing on a Headless Server

Syncthing can run just fine on a headless machine, with a caveat - each user requires a running instance. (This is the case as far as I know, I don't know if a multiuser version is in the works at the moment.) Also, on my laptops and desktop, I start it with my desktop environment, whereas my server doesn't have a GUI installed. I'd like it to start up on boot, but running as my user.

These instructions are from the Syncthing documentation for autostarting on Linux. I'm running this on Debian 10 on a single board computer (PC Engines Alix, an i386 board), but it should work on a Raspberry Pi as well. In fact, with a Pi 3 or 4, it would probably run better. I'm assuming you have it running and configured on one or more client machines as well.

Basically, I'm using a systemd unit file to start as a normal user. There should be one with syncthing when you installed it; I found it in /usr/lib/systemd/user/. Copy it to your home directory like this, where user is your username:

cp /usr/lib/systemd/user/syncthing.service /home/user/.config/systemd/user/

Next, as a normal user, run these commands to enable the service on boot and start it immediately:

systemctl enable syncthing@user.service
systemctl start syncthing@user.service