Running in background via SSH without root?

I’m trying to set up Syncthing on a shared server in which I don’t have root access, via SSH. I can start it up, and it runs fine, but of course, as soon as I close my terminal window or disconnect my session, it shuts down.

There are a lot of helpful scripts on here for Upstart, systemd, init.d, etc., but it looks like all of those require root/sudo access, which I don’t have.

The server is running Gentoo. Is there a way to fork syncthing to the background on launch (I really don’t mind restarting it manually as needed) via SSH?

So, of course as soon as I post this, I keep googling, and find “nohup”, which solves my problem pretty completely. Basically, start syncthing with “nohup /path/to/syncthing”. Problem solved.

Or syncthing & disown in bash

For anyone finding this post via google, the root part is a red herring.

Yep you should only use root to create the start-up script

You can use GNU screen, if its installed.

screen ./syncthing with the key combination control + a + d can you detach the session and with screen -r you get it back.

+1 using screen. The advantage is that you can still read stdout+err. I use the follow startup command which labels the screen process:

screen -S syncthing -d -m sh -c 'ionice -c 2 -n 5 nice -n 19 ~/bin/syncthing'

  • -S label: label the screen window
  • -dm: run in background
  • ionice and nice: be nice with disks and CPU because I’m actively using the machine

You can then access the backgrounded process as follows:

screen -x syncthing

Or runit.