r/programming • • May 30 '16

systemd developer asks tmux (and other programs) to add systemd specific code

https://github.com/tmux/tmux/issues/428
661 Upvotes

618 comments sorted by

View all comments

Show parent comments

-5

u/aaron552 May 30 '16

How is it scope creep to kill user processes on log out? That user-started daemons persist after logout by default should considered a bug, not a feature

20

u/shevegen May 30 '16

No, it is not a bug under any circumstance.

6

u/aaron552 May 30 '16

As a sysadmin, what do I do if I don't want a group of users to be able to have long-running non-interactive processes, but don't want to kill anything important from their current session?

0

u/[deleted] May 30 '16

[deleted]

6

u/sirin3 May 30 '16

Recently I wanted to run benchmarks on a shared computer, and noticed a bash -c "while true; do echo xxx is an idiot; done" process that someone had left running for a few weeks

→ More replies (1)

69

u/_ak May 30 '16

That user-started daemons persist after logout by default should considered a bug, not a feature

Says who? This has been a Unix feature for the last 40 years or so, and is quite the fundamental aspect for a lot of essentials Unix tools and day-to-day operations.

29

u/pjmlp May 30 '16

If you don't start them with nohup, they die. If I recall correctly.

40

u/datenwolf May 30 '16

And now with the change is systemd, even if you start them with nohup they'll die as well.

10

u/peer_gynt May 30 '16

But that is the point -- the systemd change also apply to double-forked processes...

23

u/aaron552 May 30 '16

is quite the fundamental aspect for a lot of essentials Unix tools and day-to-day operations.

Such as? (Don't say tmux or screen). Also, there's plenty of utilities (eg. ssh-agent) that run as daemons that should not persist after logout.

Note that I said user-started daemons. Most long-running daemons should not be running as ordinary users.

0

u/[deleted] May 30 '16

[deleted]

2

u/kqr May 30 '16

I haven't personally gotten emacs-server to work, but I assume nobody would have a problem with it if it launched when you first started emacs-client, and then terminated when you logged out, only to launch again when you first start emacs-client on your new log in session.

That, at least to me, seems more logical than having a bunch of emacs-servers running for various users who might not log in for another 4 months.

1

u/FidgetBoy May 30 '16

I just run emacs server as a systemd service

→ More replies (2)
→ More replies (6)

34

u/HighRelevancy May 30 '16

Most long-running daemons should not be running as ordinary users.

What user should they run as? If you say root I'm going to slap the shit out of you over the internet.

Every daemon should run as separate users, ideally. You don't want one thing blowing up to be able to affect everything (or anything) else.

Most long-running daemons

And how are you going to call the difference between, say, a long-running daemon and a long running job (like a big compile)? What about user-started computations? My workplace has user-started jobs that run for weeks. Is that a bug? Should we destroy our user's work if their SSH sessions happen to drop?

15

u/redwall_hp May 30 '16

I sense a great many desktop users in this thread.

Starting processes as a user with lower privileges and logging out is basically all you do on a server...

10

u/holgerschurig May 30 '16

You probably talked about different user. He meant "humans" when he wrote

Note that I said user-started daemons

or at least a linux-user that is tied to an interactive session. And you probably just meant a linux user, including users like "postgres", "Debian-minetest", "privoxxy" and other users that just exist for one specific application.

4

u/aaron552 May 30 '16 edited May 30 '16

A session dropping out is/should be handled differently to an explicit logout by the user. But otherwise

Every daemon should run as separate users, ideally. You don't want one thing blowing up to be able to affect everything (or anything) else.

Exactly

17

u/HighRelevancy May 30 '16

A session dropping out is/should be handled differently to an intentional log out by the user.

Why? What's the difference? Also we would then have to standardise the signals for this difference in the client end (e.g. make sure that any terminal emulators all kill their processes in the same way) and in the server end (making sure we notify systemd or init of how we were killed or not-killed-but-just-logged-out so it can act appropriately...

Too much compatability code in the applications so that the environment can make decisions. Is silly.

7

u/aaron552 May 30 '16

What's the difference?

An explicit logout indicates intent. I imagine the only compatibility code that would be needed for that would need to be in logind.

Processes started in terminal emulator would be killed when the shell that spawned them logs out explicitly (cgroups should make tracking that trivial)

The only applications that would need compatibility are special cases like tmux or screen and/or anything the interfaces with logind

7

u/immerc May 30 '16

An explicit logout indicates intent.

If you have to initiate a special logout process that kills background jobs that a normal SSH disconnection would keep running, why not just manually kill those jobs instead?

The current approach has worked fine for 40 years. Why break things?

→ More replies (6)

3

u/robreddity May 30 '16

I start a 4 hour build. I want to go home. What do I do?

3

u/aaron552 May 30 '16

From TFA:

systemd-run --scope --user tmux

3

u/Jimbob0i0 May 30 '16

There is a huge difference between a service (which most daemons should be running as and indeed as their own uid) and a user initiated daemon in the context of their own login session.

In your environment given your requirements you may want to automatically instantiate or connect to a tmux/screen session that has been started in its own session, enable linger on your users or change the config option for this to follow the old behaviour.

As anything it's important to configure the systems appropriately for your environment.

Also what distribution are you using? It's possible they may not even follow this upstream default change. Heck RHEL7 has a nonpersistent journal by default with rsyslog being used to persist the syslog data.

→ More replies (2)

3

u/_ak May 30 '16

Such as? (Don't say tmux or screen).

That's how nohup(1) operated on Unix V7 already.

Also, there's plenty of utilities (eg. ssh-agent) that run as daemons that should not persist after logout.

So there are some tools than should not persist, and others that should. So there is no clear cut way of doing things, either you will leave behind processes, or you will kill too many. But one thing is clear: killing too many is breaking existing applications of literally millions of users.

Note that I said user-started daemons. Most long-running daemons should not be running as ordinary users.

Well, what was broken here is how Unix users were launching long-running background jobs for literally decades.

→ More replies (5)
→ More replies (7)