Syncthing service doesn't start automatically on boot on Linux

Hello,

I installed syncthing with apt-get on Ubuntu 17.10. However, it wasn’t starting automatically, so I used:

sudo systemctl enable syncthing@myuser.service

to set up auto launch as suggested in the documentation. But Syncthing still doesn’t start automatically, I have to manually start it each time in order to use http://localhost:8384/ in the browser.

Did I miss any setup steps?

It makes most sense to use --user to start Syncthing automatically as your regular user. Eg. use systemctl --user enable syncthing.service without sudo to enable Syncthing for the current user.

But the @ syntax should work as well if such a service file is provided. What is the output of systemctl cat syncthing@.service and systemctl status syncthing@.service?

Output of systemctl cat syncthing@.service:

# /lib/systemd/system/syncthing@.service
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %I
Documentation=man:syncthing(1)
After=network.target
Wants=syncthing-inotify@.service

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

[Install]
WantedBy=multi-user.target

systemctl status syncthing@.service:

Failed to get properties: Unit name syncthing@.service is neither a valid invocation ID nor unit name.

systemctl status syncthing@user.service:

● syncthing@user.service - Syncthing - Open Source Continuous File Synchronization for user
   Loaded: loaded (/lib/systemd/system/syncthing@.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2018-02-12 03:05:30 +06; 29min ago
     Docs: man:syncthing(1)
  Process: 1221 ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0 (code=exited, status=1/FAILURE)
 Main PID: 1221 (code=exited, status=1/FAILURE)

Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Failed with result 'exit-code'.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Service hold-off time over, scheduling restart.
Feb 12 03:05:30 pc systemd[1]: Stopped Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Start request repeated too quickly.
Feb 12 03:05:30 pc systemd[1]: Failed to start Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Unit entered failed state.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Failed with result 'exit-code'.

Looks like it couldn’t start… I checked the log file at /home/user/.config/syncthing/syncthing.log and it’s empty. Where else should I look?

The log from systemctl status is truncated too early, the interesting stuff isn’t there. Use journalctl -u syncthing@user to get the full log.

-- Logs begin at Mon 2018-02-12 03:05:27 +06, end at Mon 2018-02-12 04:15:31 +06. --
Feb 12 03:05:29 pc systemd[1]: Started Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:29 pc syncthing[997]: FATAL: mkdir /home/user/.config: permission denied
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Unit entered failed state.
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Failed with result 'exit-code'.
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Service hold-off time over, scheduling restart.
Feb 12 03:05:29 pc systemd[1]: Stopped Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:29 pc systemd[1]: Started Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:29 pc syncthing[1066]: FATAL: mkdir /home/user/.config: permission denied
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Unit entered failed state.
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Failed with result 'exit-code'.
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Service hold-off time over, scheduling restart.
Feb 12 03:05:29 pc systemd[1]: Stopped Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:29 pc systemd[1]: Started Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:29 pc syncthing[1097]: FATAL: mkdir /home/user/.config: permission denied
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Unit entered failed state.
Feb 12 03:05:29 pc systemd[1]: syncthing@user.service: Failed with result 'exit-code'.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Service hold-off time over, scheduling restart.
Feb 12 03:05:30 pc systemd[1]: Stopped Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:30 pc systemd[1]: Started Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:30 pc syncthing[1198]: FATAL: mkdir /home/user/.config: permission denied
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Unit entered failed state.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Failed with result 'exit-code'.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Service hold-off time over, scheduling restart.
Feb 12 03:05:30 pc systemd[1]: Stopped Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:30 pc systemd[1]: Started Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:30 pc syncthing[1221]: FATAL: mkdir /home/user/.config: permission denied
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Unit entered failed state.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Failed with result 'exit-code'.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Service hold-off time over, scheduling restart.
Feb 12 03:05:30 pc systemd[1]: Stopped Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Start request repeated too quickly.
Feb 12 03:05:30 pc systemd[1]: Failed to start Syncthing - Open Source Continuous File Synchronization for user.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Unit entered failed state.
Feb 12 03:05:30 pc systemd[1]: syncthing@user.service: Failed with result 'exit-code'.

Why is it trying to create ~/.config?

Because configs and db are located at ~/.config/syncthing. I suspect you’re user isn’t really called “user”, i.e. you need to replace “user” with your actual username in systemctl enable syncthing@user. Also refer to @Martchus’ earlier comment: If you only want to run syncthing when you are logged in, you want to use the --user option.

Yes, my user isn’t actually called user, I just replaced it in the logs. I’ve tried sudo systemctl enable syncthing@my_user and systemctl enable --user syncthing@my_user but that didn’t help either:

Feb 12 04:26:40 pc systemd[1063]: syncthing@multi-user.service: Failed to determine user credentials: No such process
Feb 12 04:26:40 pc systemd[1]: syncthing@multi-user.service: Main process exited, code=exited, status=217/USER
Feb 12 04:26:40 pc systemd[1]: syncthing@multi-user.service: Unit entered failed state.
Feb 12 04:26:40 pc systemd[1]: syncthing@multi-user.service: Failed with result 'exit-code'.

I have Syncthing installed on another Ubuntu 17.10 machine exactly the same way, and it starts automatically by itself there. The only difference between the two is that I use home directory encryption on the machine where it fails and on the other one I don’t. Could it have something to do with /home encryption via ecryptfs?

I don’t know ecryptfs, but I’d say that’s very likely to be the reason (due to Occam’s razor). Also if ecryptfs “mounts” the encrypted home in the clear on login, that would explain the failure when running as a system service. Running as a user service, you need to drop the @user part, so just systemctl enable --user syncthing.

Well, Syncthing doesn’t start at all if I just use systemctl enable --user syncthing, there is no mention of it in journalctl. Maybe I should just change config path via -home somehow?

You need to use --user everywhere, i.e. journalctl --user ... and systemctl --user .... If systemctl --user enable syncthing reported success, there will be information there.

As a workaround I added this to ~/.profile:

systemctl --user start syncthing.service

Now it start automatically at login. Thanks for your help!

Likely you can just add RequiresMountsFor=/home/your_user_name to your service file. I haven’t used that option myself, but maybe it will delay the start till your ecryptfs is mounted. If that works, I suppose it would be the appropriate way to start the service then.

Note that you can edit the service file conveniently using systemctl --user edit syncthing.service.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.