Syncthing As A Service

Related articles

Syncthing is an open source file syncer that synchronises files across a network. The application can be run as a Windows Service using FireDaemon, which lets you start the application automatically at boot prior to login, start multiple instances of the application and more. This HOWTO will show you how to set it up. Syncthing keeps files synchronized between two or more machines. It is ideally suited for running 'headless' in the background as the GUI is accessible from any web browser. To configure Syncthing as a Windows Service with AlwaysUp: Download and install AlwaysUp, if necessary. Otherwise, a normal service runs system-wide, which is usually not suitable for Syncthing, unless we are talking about a single-user machine. It is also impossible to control services without administrative access, unless you fiddle around with service permissions, which itself requires administrative access to begin with. Yesterday I blogged about SyncThing as an alternative to BitTorrentSync. Today a business partner asked me whether it is possible to run SyncThing as a service. The answer is definitely yes, but it requires an additional tool. As per this StackOverflow answer you can use NSSM – the Non-Sucking Service Manager to create a service that works fine.

Syncthing is an open-source file synchronization client/server application, written in Go, implementing its own, equally free Block Exchange Protocol. All transit communications between syncthing nodes are encrypted, and all nodes are uniquely identified with cryptographic certificates.

  • 2Starting Syncthing
  • 5Tips and tricks

Installation

Syncthing can be installed with the syncthing package.

Synchronization by inotify can be added with either the syncthing-inotify or the syncthing-gtk package, see #Use inotify for caveats. syncthing-gtk also provides a GTK interface, desktop notifications and integration with Nautilus, Nemo and Caja.

Starting Syncthing

Tip: You can run multiple copies of syncthing, but only one instance per user as syncthing locks the database to it. Check logs for errors related to locked database.

Run binary

Run the syncthing binary manually from a terminal.

System service

Running Syncthing as a system service ensures that it is running at startup even if the user has no active session, it is intended to be used on a server.

Enable and start the [email protected]myuser.service where myuser is the actual name of your user.

User service

Running Syncthing as a user service ensures that Syncthing only starts after the user has logged into the system (e.g., via the graphical login screen, or ssh). Thus, the user service is intended to be used on a (multiuser) desktop computer. To use the user service, start/enable the user unit syncthing.service (i.e. with the --user flag).

The systemd services need to be started for a specific user in any case, see Autostart-syncthing with systemd for detailed information on the services.

Accessing the web-interface

Tip: To access the configuration GUI for a remote computer, see the FAQ.

When Syncthing is started, a web interface will be provided by default on http://localhost:8384. If you started syncthing manually, it should open the admin page in your browser.

Configuration

After installation Syncthing already has a proper start-up configuration. You may now add new servers and/or folders by visiting the web interface. For detailed instructions on how to set up a simple network, read Syncthing's getting started.

After a successful first start, it will create the default repository at ~/Sync. You can see this in the web admin interface. On the right is the list of nodes you have added. On the left is the list of repositories, which are folders you can choose to share with other nodes.

To add another node, click 'Add Node' underneath the list of nodes. You will be prompted for their Node ID (which can be found on the other machine by clicking Edit > Show ID) as well as a short name and the address.If you specify 'dynamic' for the address, the syncthing announce server will be used to automatically exchange addresses between nodes. If you want to know more about Node IDs, including the cryptographic implications, you can read the appropriate Syncthing documentation page.

After saving the configuration, you will be prompted to restart the syncthing server, and once restarted, the changes will be applied.

Next, you can either change the configuration of the default node (click its name and then Edit), or create a new one to share data with. Simply tick the node you wish to share the data with, and they will have permission to access it.

Tips and tricks

Use inotify

Inotify (inode notify) is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes to applications. Syncthing does not support inotify yet but there is an official extension module which talks to the Syncthing REST API. The usage of inotify avoids expensive rescans every minute. The inotify extension can be installed with the syncthing-inotify package. Restart the syncthing service (user or system) for changes to take effect.

Alternatively, inotify support is provided by syncthing-gtk (which does not depend on syncthing-inotify) but in this case inotify will only work while the GUI is running.

Run a Relay

This article or section needs language, wiki syntax or style improvements.

Since version 0.12 Syncthing has the ability to connect two devices via a relay when there exists no direct path between them. There is a default set of relays that is used out of the box. Relayed connections are encrypted in the usual manner, end to end, so the relay has no more insight into the connection than any other random eavesdropper on the internet [1]. To run a relay install syncthing-relaysrv, then start and enable the syncthing-relaysrv.service service.

There is also a git version in the AUR. More information about the syncthing-relaysrv-gitAUR package are available in the Syncthing forum.

Per default the relay joins the Syncthing relay pool and is publicy available. Rate limiting and other options can be configured via command line flags (check syncthing-relaysrv -help). To edit the command line flags just create a drop-in snippet for syncthing-relaysrv.service and replace the ExecStart directive:

A traffic statistics page is available at port 22070, e.g. http://78.47.248.86:22070/status.

Stop journal spam

Syncthing can be quite noisy even while it isn't doing anything. The service ExecStart can be overridden like this to filter output directly without an extra script (adjust 'grep' as needed):

Discovery Server

The Syncthing Discovery Server is available in the AUR under syncthing-discosrvAUR. Documentation is provided here.

Note, that the discovery server requires certificates to run, which should ideally be placed in /var/discosrv, and the user/group syncthing needs permissions to able to read the certificate files. Currently, you will need to edit the systemd unit file to correctly point to the certificates (as well as any other configuration changes you want to undertake, see list).

To point the client at your discovery server, change the Global Discovery Servers variable under Settings, to point to https://yourserver:8443/ (default port) or whatever port you have reconfigured to. The variable takes a comma-seperated list of discovery servers, it is possible to include multiple ones, including the default one.

If you are using self-signed certificates, the client will refuse to connect unless you append the discovery server ID to its domain. The ID is printed to stdout upon launching the discovery server. Amend the Global Discovery Servers entry to add the ID: https://yourserver.com:8443/?id=AAAAAAA-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-GGGGGGG-HHHHHHH.

Troubleshooting

See Debugging syncthing.

Retrieved from 'https://wiki.archlinux.org/index.php?title=Syncthing&oldid=468954'

Disclaimer added due to request.

**Please note that anytime you SSH into your device you can cause an issue**

With out further ado, the WD My Cloud is running a variant of Debain linux. Meaning that you can run su commands that may update packages or configurations, and or delete / modify important files. Nothing that a dd can’t fix however.

With that said. This guide will not do any of those things, unless you of course choose to downgrade the firmware. Again not a big deal if you are careful. This guide is like telling a standalone program to run at boot.

More details:

This is a simple guide to get syncthing to startup as a service and run at boot:

Must be on firmware < 4.00?? Maybe not running on latest firmware.

Arch

Step 1:
I created a share on the My Cloud Shares called Tools
You can set this up via the web page UI. Navigate in the browser to the WD’s ip address.
Enable SSH in settings

Step 2:
First you need to have the ARM7 binary file saved on the WD Drive.
Download file https://github.com/syncthing/syncthing/releases
Extract the file twice (I used 7zip) you are looking for the file named syncthing
I saved the file to /shares/Tools/ (copy to folder via windows)

Step 3:
Using putty SSH login to WD
user: root
password: welc0me

Step 4:

Step 5:

Wait for Syncthing to setup.

Step 6:

Modify the config file

Or what ever IP you are using to connect to the WD UI.
I have set my device up to be a static IP at 192.168.1.25

Step 7:
Press Ctrl + x
Y to save
And Enter to save the file as named

Step 8:
You will need to move the file to the /etc/usr/local/bin

Step 9:

Step 10:
Paste this script into the file :
https://discourse.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402

Service

Step 11:
ctrl + x – to exit
y – to save
enter – confirm file name

Step 12:

Step 13:
Copy and paste like before in the previous step

Step 13:
ctrl + x – to exit
y – to save
enter – confirm file name

Step 14:

Step 15:

Step 16:

Start Syncthing As A Service

Step 17:
I like to use reboot command in terminal, but it has caused a few issues. The better way is to reboot the device via the WD UI.