Another autostart question


I have an Ubuntu Mate 20.04 desktop with two users running Syncthing V1.18.3 installed from the Mate Software boutique. If possible I want to have Syncthing start and stop when either user logs in and out.

I have tried adding a Syncthing autostart for each user with the Mate GUI (ControlCentre>Personal>Startup Applications) using the command /usr/bin/syncthing serve --no-browser –logfile=default

While this worked to start Syncthing at the first login after boot, it limited Syncthing to whichever user was the first to login. The other user would then need to reboot the computer and be the first to login to get their files to sync.

I have also tried changing one user configuration by deleting the GUI autostart and running the following commands, but this didn’t alter the behavior I was getting from both users starting via the GUI autostart; systemctl enable syncthing@myuser.service and systemctl start syncthing@myuser.service

I had a look at the “Starting Syncthing Automatically” page which has a sub heading outlining How to set up a user service at Starting Syncthing Automatically — Syncthing v1 documentation .

I have found the Syncthing/etc/linux-systemd/user/syncthing.service file ( ) but I don’t know what to do with the instruction asking that the syncthing.service file be added to the load path of the user instance.

Also, am I correct in thinking I need to make the systemd and user files where they don’t already exist in the path ~/.config/systemd/user/.

Any help -direction is appreciated


Basically you don’t need to mock around with systemd files manually if your distribution already includes them. Judging by your description of a syncthing@username.service unit working alright, you just need to disable that again, then carry out step 3 from the “How to set up a user service” section. That’s all and should provide exactly the user experience you desire. Just make sure the users actually log out and don’t use any “switch user” functionality where in effect both users are logged on simultaneously.

If your distro provides the systemd service files for Syncthing, you can skip step #2 when you’re setting up either the system service or the user service, as described below.

This is not systemd related at all. If you are using Mate utilities, you might as well use mate utilities for autostart.

That seems sensible. However syncthing provides desktop entries which can be used for autostart directly. Ideally whatever the Mate Software boutique does, should put them in place already so you only need to choose them, not provide the command:

That’s most likely due to port collisions: When Syncthing starts for the very first time, it does check for collisions and chooses a free port, however it won’t anymore later on. So likely for all users they started once when no other instances were running, and got a GUI port of 8384. Now they can’t start if they are second because the first is already using it. You should change that port plus the listen address port to make sure they are unique (I usually just use 8384, 8385, … and 22000, 22001, …).

1 Like

I understood the intention was that they only run while the user is logged on, then stops on logout so the ports are free for the other user. That’s easily possibly with systemd user services.

But I don’t know if an instance autostarted by the desktop environment will be terminated on logout? It might just keep running in the background, so that’s when using different ports becomes necessary.

My bad, I assumed DEs/XDG autostart would do the sane thing and stop user autostart applications on logout. I tested it and at least for KDE that indeed does not happen: Autostarted processes keep running after logout.

However systemd user sessions may also persist after logout, depending on the KillUserProcesses config in /etc/systemd, which apparently is set to no by default in many systems (it is on debian and arch, not sure if thats a distribution or upstream default).

In any case I think the safest option is ensuring different ports for different users.

Thanks for the replies.

Just to confirm, in order to remove my earlier attempts with sytemctl enable syncthing@myuser.service and systemctl and systemctl start syncthing@myuser.service am I correct in thinking I just need to run

systemctl stop syncthing@myuser.service

systemctl disable syncthing@myuser.service

But changing the Syncthing port number… how is that done? Would that be achieved in the Advanced Configuration>Options>Local Announce Port field?

Or just systemctl disable --now … on a recent enough system. And yes, ports are configured in Syncthing’s settings. However, there’s not “the” Syncthing port number because it uses different ports for different things (see Firewall Setup — Syncthing v1 documentation and The GUI Listen Address — Syncthing v1 documentation).

Thanks for the input Martchus and the links When I saw the Firewall Setup link I realised what I was forgetting… :thinking: Ports are changed and it is all working correctly now

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