How to start it in background on Debian?

When I start syncthing on the Raspberry there is a lot of output to the console. I tried putting it into background with syncthing & but this is not working. I did not set up a systemctl service yet (too complicated, not sure where to put file etc.).

Is there a simple way to manually start it in the background? I can not find anything related with syncthin --help.

EDIT: I just recognised that I still have a process running after shutting down the console output with CTRL C. This was the instance I started with syncthing &. Does this mean it runs in background and is doing fine and I just canceled the console output? That would be okay.

Also, I suspect I can run it on startup in /etc/rc.local this way, right? The output will just get lost, but the process will run.

cp /usr/lib/systemd/system/syncthing@.service /usr/lib/systemd/system/syncthing.service

Edit syncthing.service and set …user=root…

systemctl daemon-reload

systemctl enable syncthing

systemctl start syncthing

Or install from our apt source and just systemctl start it.

Thanks for the fast reply. I installed using this guide on Raspberry Pi with Debian Buster via Apt but sudo systemctl start syncthing gives error: Failed to start syncthing.service: Unit syncthing.service not found.

Also /usr/lib/systemd/system/ is not present. Content of /usr/lib/systemd on my Raspberry is

  • catalog
  • scripts
  • user
  • user-environment-generators
  • user-generators
  • user-preset

EDIT: Just found the file syncthing.service under the subdirectory user. Why is it not found by the systemctl command then?

Syncthing’s apt repository installs two default sytemd service files:

  • A sytem service file and
  • A user service file

Both are disabled by default. The sytem service is located at /lib/systemd/system/syncthing@.service. The user service is located at /usr/lib/systemd/user/syncthing.service (paths may differ depending on distro or config, but those are debian defaults).

You can enable the system service using systemctl enable syncthing@<user>, where <user> is the user syncthing should run as.

More info can be found in the docs.

This is the user service file. If you want to use that, you probably need to specify user mode in systemd (systemctl --user)

Thanks! Your paths are correct. @Catfriend1 had two typos in both of them but thanks of course for the hint! After enabling (with sudo) I had to start it with sudo systemctl start syncthing@<user>. I never did give it a user before, so I did not know. It’s probably because the file has no user set and putting root in /lib/systemd/system/syncthing@.service should also work then.

EDIT: I just was wondering why other services start with a dedicated user without me having to bother with it and I found that e.g. logitechmediaserver, which I installed from source is in /run/systemd/generator.late/ and has no user in the file but a reference to /etc/init.d/logitechmediaserver. So I guess there is a config file in /etc/init.d and then there is an automatic generator.

1 Like