Getting Syncthing running with a central file server running CentOS 7 minimal setup and windows clients

I recently was tasked with the job of replacing the fileshare available with Office 365 via SharePoint with something more reliable. I won’t go into detail here as to why. Therefore I was charged to put into place a new system and I decided that we would use Syncthing.

I’d already recommended and setup a server for them running CentOS 7 so this would be used as the central server for their files and each of their work devices will connect to here. CentOS 7 was installed using a Minimal installation.

First you need to obtain the latest version of Syncthing from: Releases · syncthing/syncthing · GitHub - I used https://github.com/syncthing/syncthing/releases/download/v0.10.6/syncthing-linux-amd64-v0.10.6.tar.gz

During the minimal installation process I’d already setup an additional user. This will be the user that Syncthing will run under.

After downloading the archive extract it’s contents and move the syncthing application to /usr/local/bin/ use yum to install nano (this is my preferred editor) yum install -y nano once installed run nano /etc/systemd/system/syncthing\@.service and paste the below:

[Unit]
Description=Syncthing for %i

[Service]
Type=simple
User=%i
ExecStart=/usr/local/bin/syncthing
WorkingDirectory=%h

[Install]
WantedBy=multi-user.target

Press Ctrl+x and then y to save the file.

You will need to install these deps first as it’s the minimal installation:

yum install -y policycoreutils-python

Run the following commands to allow Syncthing through the firewall:

firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=22000/tcp --permanent
firewall-cmd --reload

Start the Syncthing service:

systemctl start syncthing@<username>

You will now need to adjust the configuration that’s been generated under /home/<username>/.config/syncthing/config.xml and then restart the Syncthing service

systemctl restart syncthing@<username>

If you want Syncthing to start at boot (we did) then

systemctl enable syncthing@<username>

Now for the clients these are Windows devices, the most notable problem here is the console window so I came across the Syncthing-Tray applciation: Releases · alex2108/syncthing-tray · GitHub

Download that and NSSM http://nssm.cc/release/nssm-2.24.zip

I then put the content of the NSSM zip into it’s own directory with the Windows version of syncthing the syncthing-tray.exe from the other archive you just downloaded.

I then created 2 batch files:

install.bat

@echo off
cd %~dp0
nssm-2.24\win64\nssm.exe install Syncthing

remove.bat

@echo off
cd %~dp0
nssm-2.24\win64\nssm.exe remove Syncthing confirm

and created a config folder and a log folder. You should then end up with a setup looking like the below:

image

I put mine into C:\Syncthing.

Run the install.bat as an administrator and then set the path to the Syncthing executable and arguments -home C:\Syncthing\config\, also for logging I set stdout and stderror to output a file to the log folder so I can see the console output incase anything goes wrong and I can report to GitHub. I also set an environment variable STTRACE=net.

To get the tray application to run on start-up (as what was needed for all their work devices) I created a shortcut to the syncthing-tray.exe in C:\ProgramData\Microsoft\Windows\Start Menu (most of their devices are running Windows 8.1). Right click the shortcut and change the path of the shortcut and add the -i switch if you’re running Syncthing over SSL on the WebGUI.

If your server is behind a firewall (as ours is as I set it up) make sure you forward the ports on that too.

Hope this helps people :smile:

Cheers

EDIT: If you’d like to use debugging as we do then edit the file: /etc/systemd/system/syncthing\@.service and add the following line in the [Service] section under User=

EnvironmentFile=/etc/sysconfig/syncthing

Type the following in the terminal

echo STTRACE=net,discovery >> /etc/sysconfig/syncthing
systemctl restart syncthing@<username>

You can view the recent output by running

systemctl status -l syncthing@<username>

or

journalctl -u syncthing@<username> --no-pager -l

You can follow output with:

journalctl -u syncthing@<username> -l -f
5 Likes

Hi, I found your message Googling for this! I’m trying out ST on CentOS 7, but I’m stuck with a problem on autostart.

Problem

systemctl start syncthing@root works flawlessly.

systemctl enable syncthing@root doesn’t and spits:

Failed to issue method call: No such file or directory

Context

ST is deployed in /home/syncthing. The folder is:

drwxr-xr-x  3 root   root    145 May  2 09:21 syncthing

Files in said folder are:

drwxr-xr-x 7 root root      113 May  2 09:21 etc
-rwxr-xr-x 1 root root 11197978 May  2 09:24 syncthing
-rw-r--r-- 1 root root       33 May  2 09:21 syncthing.md5

In /etc/systemd/system I’ve:

lrwxrwxrwx  1 root root   59 May  2 09:39 syncthing@.service -> /home/syncthing/etc/linux-systemd/system/syncthing@.service

The unit file comes straight form the downloaded ST package:

[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %I
Documentation=https://github.com/syncthing/syncthing/wiki
After=network.target

[Service]
User=%i
Environment=STNORESTART=yes
ExecStart=/usr/bin/syncthing -no-browser -logflags=0
Restart=on-failure
SuccessExitStatus=2 3 4
RestartForceExitStatus=3 4

[Install]
WantedBy=multi-user.target

Said /usr/bin/syncthing is a symlink to the binary executable in my deploy folder

lrwxrwxrwx    1 root root         25 May  2 09:43 syncthing -> /home/syncthing/syncthing

Ok, I just found out where the problem lies. You cannot systemctl enable a symlink :confused:

I replaced the unit symlink with the file itself and not it works… good luck remembering to keep that file up-to-date…

1 Like

Sorry this must have been the longest time I haven’t logged into these forums… Glad you got it sorted!

The guide does need updating a bit… Especially since there are start-up scripts included now, maybe I should use parts from that in the service file.

I will be updating this over the next couple of days as I’ve now updated our whole cluster to Syncthing v0.11.2 with SyncTrayzor (Portable) by @canton7 since it is far better than Syncthing-Tray (sorry Alex).