6

I use systemd to start most of my processes for a desktop session: xmonad (the window manager), emacs daemon, a tmux session, etc.

Listing my users processes with loginctl user-status consequently only shows a handful of processes under the session:

  Unit: user-1000.slice
        ├─session-5.scope
        │ ├─4740 lightdm --session-child 13 16
        │ ├─5047 systemctl --user --wait start xmonad-systemd-session.target
        │ └─5497 /usr/bin/ssh-agent /usr/bin/im-launch xmonad-systemd-session
        └─user@1000.service

Almost all my processes run outside of the session below user@1000.service. That means running loginctl session-status from tmux gives:

Could not get properties: Caller does not belong to any known session

I would like to tell systemd to start certain services under a particular login session. Ideally, in my session starter script I would write:

exec systemctl --user --wait \
    --scope $MY_DESKTOP_SESSION start xmonad-systemd-session.target

However there is no --scope option nor would I know how to get the scope name.

I run systemd 240 on a Debian-ish (inhouse) distro with libpam-systemd and dbus-user-session.

Schlueter
  • 151
  • What exactly do you mean by "Almost all my processes run outside of the session below user@1000.service"? I have services which display in the output of loginctl user-status under my user@1000.service, but they're literally in the output, which it doesn't sound like yours are. – Schlueter Oct 24 '19 at 03:58

1 Answers1

1

I'm not sure systemd allows having services inside a scope that already contains processes. According to the control group interface documentation one scope or service cannot have both processes and other scopes/services as children. (Or actually it says slices contain only services and scopes, and services and scopes contain processes. But my system doesn't seem to follow those docs as I have services inside my user@1000.service.)

You can run processes inside your session scope by having them started from something already in that session. In Gnome, commands started from Alt+F2 or from e.g. an xterm (but not a gnome-terminal, which runs as its own service) run inside the session scope. I'm not aware of any other way to get a process in a scope. See also this.

To me it is really obvious that you sometimes want to have a service inside of your session, (i.e. have it killed if the session is killed, have multiple copies if you have multiple sessions) so if that doesn't exist I hope it will be built some time.

JanKanis
  • 1,069
  • 2
    To explain what's happening with user@1000.service, the user@.service template delegates cgroup controllers to the process it starts, which is a per-user instance of systemd. While the cgroup hierarchy might make it look like that, the units below the user service don't belong to the system-wide systemd, i.e. PID 1. If you do a regular systemctl status on these, you will get an error because it doesn't know they exist. You have to use systemctl --user status to talk to your user's instance of systemd. – FallenWarrior Nov 26 '21 at 14:14