Keeping Syncthing Running: Systemd & regular /etc/init.d

When STNORESTART=yes is set, Syncthing/Pulse returns 3 as an exit code and Systemd will not restart it unless you add SuccessExitStatus=3 to the service file. A restart from the web gui would not work otherwise.

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

[Service]
User=%i
Environment=STNORESTART=yes
ExecStart=/usr/bin/syncthing
Restart=on-success
SuccessExitStatus=3 

[Install]
WantedBy=multi-user.target

I am running OpenSuse 13.1 and I have no experience in systemd services and would like to explain the problems I had when I tried this guide.

Tried multiple different options including copying syncthing.service to systemd/user folder and so on.

$systemctl start syncthing Failed to issue method call

$systemctl --user start syncthing Failed to get D-Bus connection: Did not receive a reply

The solutions to my problem was provided here in proper order:

  1. Copy the systemd service from first post and save as syncthing@.service in folder: /etc/systemd/system/multi-user.target.wants/
  2. $systemctl enable syncthing@$USER.service
  3. $systemctl start syncthing@$USER.service

Now everything seems to be working fine.

Stopping/restarting would be a PITA. Especially the latter.

Youā€™re supposed to run it as sudo systemctl start syncthing@USERNAME, not systemctl --user.

What I just said above applies. Also, the ArchLinux package actually displays a message post-installation telling you exactly this.

I did not miss the install message. Do you know why this is? I would like it better, when this service is controlled by the user itself, that is why I tried to get it working with systemctl --user.

Is there any reason why you canā€™t just sudo systemctl? The service runs as the user anyway. And it can restart itself once itā€™s started. (or you can kill it and have systemd restart it for you).

Like I said, as a user space process it should be controlled by the user. The user can not stop or start any services of this type, because the service was set by the super user. Correct if I am wrong but I think that the service is started at system start and therefore can affect the overall performance depending on the number of users using syncthing, repositories and so on. The user service manager (systemctl --user) is started on the first log in of the according user and its logs can only be viewed by the according user (privacy). I know for a single user system there is no difference but for multi user systems it makes sense to use the user service manager and I am always glad to keep my activities in user space :slight_smile:

As I said before, the above script runs the service as the configured your (eg: your user, not root), even if itā€™s started by root (systemd will change user before starting the process). (Iā€™m assuming thatā€™s what you refer to with ā€œuser spaceā€, since syncthing canā€™t run outside user space).

I do agree on the multi-user point; syncthing may degrade performance on shared hosts or have other undesired effects. Just also keep in mind that by running with systemd --user syncthing will not sync files until you log in on more than one host simultaneously.

1 Like

If you use a package, then the systemd script comes ready to use (for openSUSE)

See https://pulse-forum.ind.ie/t/opensuse-package-for-syncthing/189/26

I would like to tweak the init.d script for debian, in order to keep logs in a file. How can I do this ?

1 Like

I have debian, used this init.d script mixed with this installation guide. Result is that I have syncthing running as a dameon/service by user syncthing. It was working ok for few days, but now I cannot connect to web guiā€¦ when I go to my IP:port there is no response, it jsut loads forever.

The syncthing pseems to be running because:

syncthing@cedrus:$ sudo service syncthing status
syncthing for USER syncthing: running (pid 2268024987)

It looks like for whatever reason the /etc/init/syncthing.conf is missingā€¦ there is no such fileā€¦

Any ideas what went wrong and how to correct it?

To reply to myself.

I find out that the syncthing confing is actually in home directory ./config/syncthing/config.xml

there in the config in the gui section was some ā€œ> api keyā€ which i dont remember setting, so I removed it

Then for whatever reason the service syncthing status was returning 6 processes, so I killed them all, and restarted as service syncthing start

and it works againā€¦

wonder why this all happenedā€¦

I am evaluating syncthing as a replacement for my dropbox, but so far it is too much geeky, expecially the server part (syncthing running as daemon on my little debian box)ā€¦

A light modified version of the debian init.d script can be found here: http://download.prodigy7.de/files/programs/any/syncthing/syncthing Output from stdout are redirected to logfile in /var/log. Please add init script to package.

Please make a pull request.