Keep a process alive after logging out from local (not ssh) session

3

Is it possible to keep a server process running after I logout of the machine?

Normally I would use screen, tmux, or nohup, all of which work when I am NOT using ssh, but am using the machine locally. (It also is running the Gnome Desktop.)

So, is there anyway to start a server process when you are logged in locally to a machine?

Leif Andersen

Posted 2016-08-31T17:44:54.953

Reputation: 135

All of the options you listed should work fine when you're logged in locally. What seems to be the problem with them? – jjlin – 2016-08-31T17:50:07.220

I can disconnect from the screen just fine. However, when I log out, the screen session seems to die. – Leif Andersen – 2016-08-31T17:52:01.980

Are you able to start the process under another user account? It seems when you logout, it stops all running processes under your name. – mt025 – 2016-08-31T17:58:55.017

There is only one user on the machine. If the server is started from ssh, it continues to run even after log out. – Leif Andersen – 2016-08-31T17:59:57.953

Which distro is this? There's probably some way to disable the part where it kills all your processes on logout... – jjlin – 2016-08-31T18:51:48.723

The distro is Fedora. – Leif Andersen – 2016-08-31T18:53:25.487

Are you using the F25 alpha? We're trying a new systemd feature... and it has some quirks. What does loginctl show-session -p KillUserProcesses show you? – mattdm – 2016-09-01T00:28:15.523

Answers

2

As of systemd 230, KillUserProcesses is enabled by default:

https://github.com/systemd/systemd/commit/97e5530cf2076a2b4fc55755917262607aaa6338

You can change this by editing /etc/systemd/logind.conf, e.g. by setting KillUserProcesses=no to disable this behavior globally, or setting KillExcludeUsers=<your-username> to exclude your username from this behavior.

Or you can work around this on an ad hoc basis by starting your server process using systemd-run --scope --user <executable>. You can find more details about this in Example 5. Start screen as a user service towards the bottom of systemd-run(1).

jjlin

Posted 2016-08-31T17:44:54.953

Reputation: 12 964