After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 759115 - Add systemd user .service file
Add systemd user .service file
Status: RESOLVED FIXED
Product: gnome-terminal
Classification: Core
Component: general
3.18.x
Other Linux
: Normal normal
: ---
Assigned To: GNOME Terminal Maintainers
GNOME Terminal Maintainers
: 759633 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-12-07 11:44 UTC by Laurent Bigonville
Modified: 2016-05-11 12:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add a systemd user service file for gnome-terminal-server (2.50 KB, patch)
2016-04-12 21:17 UTC, Laurent Bigonville
none Details | Review
Add a systemd user service for the terminal server (2.97 KB, patch)
2016-04-12 21:34 UTC, Simon McVittie
none Details | Review
Make systemd user unit presence and location configurable (3.05 KB, patch)
2016-04-12 21:36 UTC, Simon McVittie
none Details | Review
Add a systemd user service for the terminal server (2.59 KB, patch)
2016-04-13 06:45 UTC, Simon McVittie
committed Details | Review
Make systemd user unit presence and location configurable (3.56 KB, patch)
2016-04-13 06:46 UTC, Simon McVittie
none Details | Review

Description Laurent Bigonville 2015-12-07 11:44:46 UTC
Hi,

This is somehow related to the bug #744736

When using systemd user session manager, the gnome-terminal-server process and all the process started in the termnials are started as children of the dbus.service process (that can be checked with systemctl --user status)

Adding a .service file for gnome-terminal-server should fix that
Comment 1 Christian Persch 2016-01-10 15:22:03 UTC
g-t-s is dbus activated, which requires a service file to work, so it already has one:

$ cat /usr/share/dbus-1/services/org.gnome.Terminal.service 
[D-BUS Service]
Name=org.gnome.Terminal
Exec=/usr/libexec/gnome-terminal-server
Comment 2 Laurent Bigonville 2016-01-10 18:49:58 UTC
I was talking here about a _systemd_ .service file
Comment 3 Christian Persch 2016-02-14 10:07:13 UTC
*** Bug 759633 has been marked as a duplicate of this bug. ***
Comment 4 Christian Persch 2016-02-14 10:07:47 UTC
Got a patch?
Comment 5 Sam Morris 2016-03-13 09:50:27 UTC
Dupe of bug 744736?
Comment 6 Christian Persch 2016-03-13 09:55:44 UTC
No.
Comment 7 Simon McVittie 2016-04-12 18:21:45 UTC
This is related to the thread that prompted #744736, though: as noted in that thread (<https://lists.freedesktop.org/archives/dbus/2015-February/016540.html>), if #744736 isn't implemented first, the systemd user service would need to have KillMode=main.

I might implement this just so that my terminal-based processes stop showing up in dbus.service :-)
Comment 8 Laurent Bigonville 2016-04-12 21:17:52 UTC
Created attachment 325824 [details] [review]
Add a systemd user service file for gnome-terminal-server

With this service file, the processes started using gnome-terminal will
not be classified in the same cgroup as dbus.
Comment 9 Simon McVittie 2016-04-12 21:34:53 UTC
Created attachment 325825 [details] [review]
Add a systemd user service for the terminal server

This is used to implement the D-Bus session service if
"dbus-daemon --session" was configured to use systemd activation,
most commonly via the units installed by configuring dbus 1.10+
with --enable-user-session.

With this service, child processes such as the user's shell
end up in the cgroup .../user@UID.service/org.gnome.Terminal.service
instead of in .../user@UID.service/dbus.service.

---

Sorry, I must have written this about the same time Laurent did... I think this one is maybe a little better so I'm attaching it anyway.

This is the simple version with no switchable path or optional installation of systemd services. Some maintainers prefer this, some prefer to have the configure option. I personally don't think the configure option is particularly useful, so I'm going to attach it separately.
Comment 10 Simon McVittie 2016-04-12 21:36:46 UTC
Created attachment 325826 [details] [review]
Make systemd user unit presence and location configurable

---

Optional add-on for Attachment #325825 [details] to add --with-systemduserunitdir=PATH and --without-systemduserunitdir. I personally don't think these are amazingly useful - installing one extra text file on non-Linux is hardly a huge burden - but some maintainers strongly prefer to have them, so apply this if desired or ignore it if not.
Comment 11 Simon McVittie 2016-04-12 21:44:30 UTC
Review of attachment 325824 [details] [review]:

::: configure.ac
@@ +156,3 @@
+  [systemduserservicedir="$withval"],
+  [systemduserservicedir='${prefix}/lib/systemd/user'])
+AC_SUBST([systemduserservicedir])

The conventional name seems to be `--with-systemduserunitdir`. I don't particularly like that name (I'd add at least a couple of extra `-` if it was my idea) but having it similar between packages seems valuable.

I don't think adding this option but not supporting `--without-systemduserunitdir` (exactly equivalent to `--with-systemduserunitdir=no`) is a good idea: if we're going to have the option at all, we might as well have both of its meanings (again, uniformity between packages).

::: src/Makefile.am
@@ +17,2 @@
 dbusservice_DATA = org.gnome.Terminal.service
+systemduserservice_DATA = gnome-terminal-server.service

I've been using a convention that the systemd service is named the same as the .desktop file, where there is one, on the basis that at one point there was some talk of having a user-unit generator taking /etc/xdg/autostart as input, which would provide/rely on that convention.

This name seems fine if the maintainer would prefer it though.

@@ +143,3 @@
 		      echo "Name=org.gnome.Terminal"; \
+		      echo "Exec=${libexecdir}/gnome-terminal-server";
+		      echo "SystemdService=gnome-terminal-server.service") > $@

This last line should not be added (or should be commented out) if the systemd service is disabled with `--without-systemduserunitdir`, because otherwise, activation would fail (if a user explicitly disables systemd integration, but later switches to systemd anyway).

@@ +148,3 @@
+	$(AM_V_GEN) ( echo "[Unit]"; \
+		      echo "Description=GNOME Terminal Emulator"; \
+		      echo "Documentation=man:gnome-terminal(1)"; \

The man page appears to be Debian-specific, so I wouldn't tend to add this unless the man page goes upstream.
Comment 12 Laurent Bigonville 2016-04-12 22:03:10 UTC
Wouldn't it be better if the systemd .service file was called gnome-terminal-server.service instead of org.gnome.Terminal.service?

Looking in the debian packages, I don't see any .service named after the bus name (gvfs for examples are named after the executable name)
Comment 13 Simon McVittie 2016-04-13 06:01:13 UTC
(In reply to Laurent Bigonville from comment #12)
> Wouldn't it be better if the systemd .service file was called
> gnome-terminal-server.service instead of org.gnome.Terminal.service?

As I said, I was basing this on the .desktop filename, since there is one.

I wouldn't mind changing this, though, even if "systemd service = desktop file" turns out to be a convention that's followed in future: getting the name right first time is less important for systemd services, because unlike desktop files, symlinks-as-aliases are understood by systemd.
Comment 14 Simon McVittie 2016-04-13 06:45:48 UTC
Created attachment 325839 [details] [review]
Add a systemd user service for the terminal server

This is used to implement the D-Bus session service if
"dbus-daemon --session" was configured to use systemd activation,
most commonly via the units installed by configuring dbus 1.10+
with --enable-user-session.

With this service, child processes such as the user's shell
end up in the cgroup .../user@UID.service/org.gnome.Terminal.service
instead of in .../user@UID.service/dbus.service.

---

Altered to use gnome-terminal-server.service for the systemd service.
Comment 15 Simon McVittie 2016-04-13 06:46:28 UTC
Created attachment 325840 [details] [review]
Make systemd user unit presence and location configurable

Installing metadata for "systemd --user" even on systems where it is
not used is very low-overhead (one small text file), but in projects
where it is made optional, the configure option is conventionally
--without-systemduserunitdir.

The same configure option also controls where the user units are to be
installed, if not disabled. In practice systemd is very likely to be
installed in /usr, so the default is correct for --prefix=/usr, and
other prefixes will require linking, copying or moving the units
into the systemd search path.

---

Longer commit message; use gnome-terminal-server.service
Comment 16 Christian Persch 2016-04-15 16:36:07 UTC
I committed the first patch, but I don't see any need to make the location configurable, so unless a strong argument for that appears, I'll pass up on the 2nd patch.

This should take care of the common case of the g-t-server being started from dbus. But when the user (or some ******* distro scripts) start g-t-server with --app-id manually, all the child processes will still end up in the wrong cgroup, wont' they? Anything we can do about that?
Comment 17 Simon McVittie 2016-04-15 16:54:10 UTC
(In reply to Christian Persch from comment #16)
> I committed the first patch, but I don't see any need to make the location
> configurable, so unless a strong argument for that appears, I'll pass up on
> the 2nd patch.

Sounds good to me. Some maintainers seem to feel really strongly that the location or install-or-not or both must be configurable, so I provided the second patch to avoid having to do another review round-trip if you rejected the simpler version. I slightly prefer not applying it - much simpler!

> This should take care of the common case of the g-t-server being started
> from dbus. But when the user (or some ******* distro scripts) start
> g-t-server with --app-id manually, all the child processes will still end up
> in the wrong cgroup, wont' they? Anything we can do about that?

Yeah, if you start g-t-server manually, it runs in whatever context you ran it in, just the same as if you run "sudo dbus-daemon --system" it won't be nicely wrapped in dbus.service. I don't think we can (or should) do anything about that.

I'm curious which distro scripts do this, and why?

If a user or distribution wants a gnome-terminal-except-not for whatever reason, they could provide their own suspiciously similar systemd unit for it, I suppose...
Comment 18 Christian Persch 2016-04-15 17:11:16 UTC
(In reply to Simon McVittie from comment #17)
> I'm curious which distro scripts do this, and why?

It's Ubuntu, of course. You'll have to ask them for the reason.
Comment 19 Christian Persch 2016-05-08 09:08:05 UTC
Cherry-picked to 3-20 too.
Comment 20 Martin Pitt 2016-05-11 10:06:46 UTC
Even with this fix this IMHO is still looks somewhat unsatisfactory, or at least weird: gnome-terminal itself and all of its children that you run in terminals are still attached to the per-user systemd instance directly, as processes that span all user sessions. But unlike "real" user services like gvfs, things run in a terminal should IMHO *not* span all sessions but be specific to the logind session that you start them under.

I. e. systemd-cgls now looks like that (shortened to only show the interesting parts):

Control group /:
└─user.slice
  └─user-1000.slice
    ├─user@1000.service
    │ ├─dbus.service
    │ │ ├─2199 /usr/bin/dbus-daemon --session --address=systemd: --nofork --n...
    │ │ ├─2462 /usr/lib/x86_64-linux-gnu/gconf/gconfd-2
    │ │ └─3116 /usr/bin/gnome-screensaver --no-daemon
    │ ├─init.scope
    │ │ ├─2139 /lib/systemd/systemd --user
    │ └─gnome-terminal-server.service
    │   ├─2394 /usr/lib/gnome-terminal/gnome-terminal-server
    │   ├─2415 bash
    │   └─3607 systemd-cgls
    └─session-c2.scope
      ├─1120 lightdm --session-child 12 19
      ├─2191 i3
      ├─2322 /usr/lib/firefox/firefox

I. e. processes started in a terminal (bash and systemd-cgls here) are detached from the logind session scope which has (and is supposed to) have all my other session processes such as firefox or the window manager (i3).

This might just be me not fully appreciating the idea of the D-Bus user session yet, but this looks highly inconsistent to me?
Comment 21 Martin Pitt 2016-05-11 10:08:09 UTC
CC'ing Lennart in case he has some input on this, as the D-Bus user session was discussed at length on a previous systemd hackfest.
Comment 22 Christian Persch 2016-05-11 10:58:52 UTC
I guess that's bug 744736 ?
Comment 23 Martin Pitt 2016-05-11 12:03:26 UTC
Somewhat related, yes. I'll follow up there, to keep the conversation on an open bug.