Syncthing server disconects when the SSH session is closed!

Hello!

As the title says, the syncthing server seems to be disconected when i close the SSH session to the server, couple of details:

  • Running an ubuntu 16.04 headless server.
  • Created a syncthing-server, and instaled the software from that user.
  • Everything works perfect when you are logged with the user, but as soon as you disconect the session, the server its out.
  • Syncthing starts properly with the machine.

systemctl --user status syncthing.service

  • syncthing.service - Syncthing - Open Source Continuous File Synchronization Loaded: loaded (/usr/lib/systemd/user/syncthing.service; enabled; vendor pres Active: active (running) since Mon 2018-01-15 23:33:25 UTC; 14s ago Docs: man:syncthing(1) Main PID: 1283 (syncthing) CGroup: /user.slice/user-1000.slice/user@1000.service/syncthing.service `-1283 /usr/bin/syncthing -no-browser -no-restart -logflags=0

What i did wrong??

You most likely have encrypted home directory, which gets unmounted/encrypted as you log off, making syncthings database disappear.

I think the issue is with running Syncthing as a user service: User services are started/stopped when a user logs in/out. If you want to run Syncthing on a server constantly you want to run it as a system service: Don’t use --user and add the username to the service (like syncthing@yourusername). You’ll need root/sudo privileges to do this.

1 Like

System service not necessarily necessary but @imsodin is (probably) right on for issue. Assuming @imsodin nailed the issue instead of @AudriusButkeviciustry try running this:

nohup /home/user/syncthing-location/syncthing > /dev/null 2>&1&

To run this automatically there are other ways to do it (.profile, ect) but easiest to have Syncthing run automatically on headless server is to set a cronjob with the above command to run every minute or every five minutes. Nothing will happen if Syncthing is already running.

This should be the correct answer, it really makes sense; will try tomorrow at the server and report back.

Hello, not encrypted, still :slight_smile:

Hello @shnappi, yeah he is probably right, will test soon. I think im going to reinstall the systemd service or the full software, and start again with “correct way” …i think? I try not to use customs scrips / commands since its more difficult for me to keep record of such things. Will report back tomorrow

Good luck. Nothing is custom above. Nohup does not require any packages and will work on all Unix systems. It basically disconnects the command from the individual SSH session so it will continue to run after the session closes. The latter part redirects the output that you will normally get from running Syncthing in a command line. This is necessary because Syncthing’s “-no-console” only works on Windows.

See the docs for using systemd, in particular, the difference between a system service (which starts on boot) and a user service (which starts when you log in).

Sorry youre right, im old and wary of new commands, never saw that one ;). You were right @schnappi, the issue was the systemd running as a user instead of a system service, i just reinstalled as the second one and everything is working perfectly, Thanks for the help!

Problem its that i was running syncthing as an user server, so when the user disconects the SSH session, the process is killed aparently.

Reinstalled synchting as a system service: sudo systemctl enable syncthing@syncthing-server.service sudo systemctl start syncthing@syncthing-server.service

And now its working perfectly, thanks everyone for the help.

PD: Will write a guide about headless server, there is some but a little outdated or incomplete.

It’s also possible to continue managing the user service without privileges if the administrator turns on “lingering” for your user, like this:

# loginctl enable-linger username

Now the user’s services will start at boot even if they are not logged in.

https://www.freedesktop.org/software/systemd/man/loginctl.html

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