[systemd-devel] Stopping a PAMName=login graphical session cleanly

Michał Sawicz michal at sawicz.net
Mon Sep 11 09:28:37 UTC 2023


Hi all,

Roughly following the setup recommended here:

https://wayland.pages.freedesktop.org/weston/toc/running-weston.html#running-weston-from-a-systemd-service

I'm building a solution for a default, always running user session. It 
works well, with one exception - how do I stop it cleanly?

A trivial example:


```ini
# /etc/systemd/system/user-session.service
[Service]
User=ubuntu
PAMName=login
TTYPath=/dev/tty1

ExecStart=/usr/bin/systemctl --user start --wait mysession.target
```

```ini
# /etc/systemd/user/mysession.target
[Unit]
BindsTo=graphical-session.target
```

Stopping user-session.service will just terminate the `systemctl` 
process and the login session - but not the components of the graphical 
session.

I thought of stopping the `graphical-session.target` instead but that's 
missing environment:
```ini
ExecStop=/usr/bin/systemctl --user stop graphical-session.target
```
```
Sep 08 07:44:50 ubuntu systemctl[1738]: Failed to connect to bus: 
$DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider 
using --machine=<user>@.host --user to connect to bus of other user)
```

I can hack XDG_RUNTIME_DIR in (though that sounds wrong), but that still 
doesn't cover the "this should be synchronous" part - it doesn't wait 
for the target (or its binds) to actually stop.

What am I missing?

Thanks!
--
Michał (Saviq) Sawicz


More information about the systemd-devel mailing list