October 11, 2016

Quick and Dirty Install SyncThing in Debian with a Systemd Service

Sync
I really like BTSync (aka “bittorrent sync” aka “Resillio”). It was a god-send considering a wanted to sync files between multiple computers and NAS, but did not want to store them in the cloud (read as: These are not he DropBoxes you are looking for.) I first tried AeroFS for a short stint, but the vendor soon shifted focus from individual to team/business oriented support. BTSync was released during this time.

I’ve been using BTSync for 2 years now. I stayed at v1.x all this time. BTSync is exactly what i want and has been working great.

When I recently had my work notebook replaced, I decided to “upgrade” BTSync to v2. I seem to likeed it more – the interface worked a little better, so i decided to upgrade BTSync on my Synology Diskstation to v2 also, but it failed to run at all . I seem to be stuck with v1.4.11. Let me be clear, v1 is not bad; It does work. But sometimes, i just can’t live with older, obsolete, and unsupported software. Also, I don’t believe the bittorrent team are freedom-hating, but it is certainly closed-source.

I’ve researched the file-syncing subject many, many, times. On several occasions, I was super close to trying open-source (freedom-loving) Syncthing, but at various times it was not quite ready. Well this time, after looking at it again, it was ready. And so was I.

So here is the quick and dirty install for debian/ubuntu with a systemd service:
(Note: If you are not using systemd, or are using an alternate OS, then there are other service options. )
# install syncthing as per http://apt.syncthing.net/ instructions
curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
echo "deb http://apt.syncthing.net/ syncthing release" | sudo tee /etc/apt/sources.list.d/syncthing.list
sudo apt-get update
sudo apt-get install syncthing

# create new service file via syncthing's systemd "system" file:
sudo curl -o /etc/systemd/system/syncthing@.service https://raw.githubusercontent.com/syncthing/syncthing/main/etc/linux-systemd/system/syncthing%40.service
sudo curl -o /etc/systemd/system/syncthing-resume.service https://raw.githubusercontent.com/syncthing/syncthing/main/etc/linux-systemd/system/syncthing-resume.service
# enable and start the syncthing per-user service user=$(whoami) sudo systemctl daemon-reload sudo systemctl enable syncthing@${user} sudo systemctl start syncthing@${user} systemctl status syncthing@${user} #launch web-UI xdg-open http:127.0.0.1:8384

To install on Synology DiskStations, use the SynoCommunity package repository.

I won’t go into the setup, but some key things are the following:

First, be sure to set a “GUI Authentication User” and “GUI Authentication Password” via the Actions>Setting menu, then restart the service.

Next, it is important to understand that a Syncthing relationship is different than BTSync. Rather than a single key that enables syncing as with BTSync, in Syncthing you will add “devices” to each system and specific share folders. You are required to add these “both-ways“. For example for two systems to sync, you will add device A to your device B, and vice-versa. If you wish to sync between three devices, device A will need both device B and C added; device B will need both device A and C added; and finally device C will need both device A and B added. During this, you may need to create the folders before-hand, and pay special attention to the folder ID (key) provided by Syncthing, as it must be the same on each end-point.

Also, I was certainly having some sync/connection issues, and after much troubleshooting, it seemed IPv6 was stopping IPv4 from being the preferred connection method. There is no documentation stating a defacto way to disable IPv6, but after reading https://docs.syncthing.net/users/config.html, i tried setting my “Sync Protocol Listen Addresses” to simply tcp://0.0.0.0, which seems to be the equivalent of saying “use IPv4 on all interfaces.” I am still uncertain if this is necessary or even proper, so use with caution. In fact, I'd recommend do not do this yourself.

With both BTSync and Syncthing, the software repeatedly scans files for hashes, and if changed, will sync updates.  These computations are a heavy burden on an ARM based NAS such as the Synology. Syncthing's default scan interval is 60 seconds.  Every 60 seconds it will scan a sync-folder for changes -- this caused my Synology to continuously thrash the disks.  In an effort to reduce this heavy activity, i went to the advanced settings, chose my folder(s) and set rescanIntervalS to 900 seconds (15 minutes). Since my Synology is more of a backup device and I do not edit these files directly, this is a much better sync-interval.

You should certainly visit the Syncthing Documentation for your needs. Also, You may or may not need to open or port-forward TCP 22000 and UDP 21027 depending on your network environment.

As always, Good Luck!

- - -


Please consider crypto tipping:
  

2 comments:

  1. change it from system-service to user-service

    systemctl status syncthing@$USER.service
    systemctl status syncthing-resume.service

    sudo systemctl stop syncthing@$USER.service
    # sudo systemctl stop syncthing-resume.service ## not enabled by default

    sudo systemctl disable syncthing@$USER.service
    sudo systemctl disable syncthing-resume.service

    ls .config/systemd/user/
    cd .config/systemd/user/

    cp -p /etc/systemd/system/syncthing* ./ #depending on system (debian here)
    cp -p /lib/systemd/system/syncthing* ./ #depending on system (ubuntu here)

    sudo rm /etc/systemd/system/syncthing@.service
    sudo rm /etc/systemd/system/syncthing-resume.service

    sudo rm /lib/systemd/system/syncthing@.service
    sudo rm /lib/systemd/system/syncthing-resume.service

    systemctl daemon-reload
    systemctl reset-failed

    sudo loginctl enable-linger $USER

    ## systemctl --user enable syncthing.service ## optional, thinking of death, will i want it running when employer boots machine?
    systemctl --user start syncthing.service ## manually run it or script it to run upon login?
    systemctl --user status syncthing.service

    ReplyDelete

Comments, Suggestions or "Thank you's" Invited! If you have used this info in any way, please comment below and link/link-back to your project (if applicable). Please Share.
I accept Bitcoin tips of ANY amount to: 1GS3XWJCTWU7fnM4vfzerrVAxmnMFnhysL
I accept Litecoin tips of ANY amount to: LTBvVxRdv2Lz9T41UzqNrAVVNw4wz3kKYk