Syncthing on Arch Linux

Author: akeil
Date: 2014-12-10
Version: 1

Syncthing [1] is an open source tool which keeps files on different machines in sync.

Installation

For Arch Linux Syncthing is available in the community repository [3] and can be installed easily:

# pacman -S syncthing

The Syncthing package installs a .service file at /usr/lib/systemd/system/syncthing@.service.

[Unit]
Description=Syncthing service for %i
After=network.target

[Service]
User=%i
Environment=STNORESTART=yes
ExecStart=/usr/bin/syncthing
Restart=always

[Install]
WantedBy=multi-user.target

When enabling or starting the service, supply the user under which syncthing will run:

# systemctl start syncthing@yourname
# systemctl enable syncthing@yourname

Configuration

Configuration is located at ~/.config/syncthing/. The directory and config files inside it will be created when Syncthing is first started. It is described in detail in the Syncthing documentation [2].

The config.xml can either be edited via the web GUI or manually. By default, the Web GUI is only reachable from the same machine.

If Syncthing is installed on a machine without a desktop, one can either edit the configuration manually for all tasks or at least to make the GUI available on the network. Manual configuration will also be necessary if you want to change the port number under which the GUI is available, for example when the default port 8080 is already in use.

<configuration version="6">
    ...
    <gui enabled="true" tls="true">
        <!-- default: 127.0.0.1:8080 -->
        <address>0.0.0.0:8888</address>
    </gui>
    ...
</configuration>

The first thing you might want to do is to remove the ~/Sync/ directory that was created on startup and replace it with something else.

# systemctl stop syncthing@yourname
$ rm -r ~/Sync

Edit the config file to include the directories to sync:

<configuration version="6">
    <folder id="default" path="/home/yourname/sync-folder" ro="false" rescanIntervalS="60" ignorePerms="false">
        <device id="[ID-1]"></device>
        <versioning></versioning>
        <lenientMtimes>false</lenientMtimes>
        <copiers>0</copiers>
        <pullers>0</pullers>
        <finishers>0</finishers>
    </folder>
    ...
</configuration>

Create more <folder> elements if you want to sync other directories.

Changes will take effect when Syncthing is restarted:

# systemctl restart syncthing@yourname

Start Syncing

Repeat installation and configuration on other machines you which to keep in sync. On each machine, Syncthing must be started at least once to determine the device ID for that machine.

Edit the config file to include the new devices and add the device to each folder you want to sync:

<configuration version="6">
    <folder id="notes" path="/home/akeil/notes" ro="false" rescanIntervalS="60" ignorePerms="false">
        <!-- the ID of the local device -->
        <device id="[ID-1]"></device>
        <!-- one or more IDs of remote devices -->
        <device id="[ID-2]"></device>
        <versioning></versioning>
        <lenientMtimes>false</lenientMtimes>
        <copiers>1</copiers>
        <pullers>16</pullers>
        <finishers>1</finishers>
    </folder>
    <!-- the local device -->
    <device id="[ID-1]" name="other-machine" compression="true" introducer="false">
        <address>dynamic</address>
    </device>
    <!-- remote devices to sync with -->
    <device id="[ID-1] name="home" compression="true" introducer="false">
        <address>dynamic</address>
    </device>
    ...
</configuration>

Restart syncthing:

# systemctl restart syncthing@yourname

Note

You must create <device> elements on both machines. (inside the <folder>'s you wish to sync and in the general section of known devices.).

If not, entries like this appear in the log and nothing is synced:

[...] Connection from 192.168.1.100:12345 with unknown device ID [ID-1];

Logfiles (Journal)

View logs with:

$ journalctl --unit syncthing@yourname

Or

$ systemctl status syncthing@yourname