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:
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
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