Kim Klotz
3 months
Andreas Vöst
7 months
Marc Dierig
10 months
Moritz Kraus
1 year
Stefan Xenopol
1 year

Desktop notification for failed systemd user services

Posted . Visible to the public.

You can execute systemctl --user --failed to check for failed systemd user units. But let's face it: It's inconvenient and you'll probably miss failures. Better use desktop notifications.

~/.config/systemd/user/service.d/user-failure-notification.conf

Add a OnFailure handler to all user units.

[Unit]
OnFailure=user-failure-notification@%n

~/.config/systemd/user/user-failure-notification@.service

Add a template service unit which sends the notifications. The instance variable %i is replaced by the calling unit.

[Unit]
Description=Send a notification about a failed systemd user unit

[Service]
ExecStart=/usr/bin/notify-send -u critical -a systemd "Failed unit: %i"

Activate

systemctl --user daemon-reload

Check

Run systemctl --user cat $unit to verify the config:

$ systemctl --user cat pipewire.service

# /usr/lib/systemd/user/pipewire.service
[Unit]
Description=PipeWire Multimedia Service
Requires=pipewire.socket
ConditionUser=!root

[Service]
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
RestrictNamespaces=yes
SystemCallArchitectures=native
SystemCallFilter=@system-service
Type=simple
ExecStart=/usr/bin/pipewire
Restart=on-failure
Slice=session.slice

[Install]
Also=pipewire.socket
WantedBy=default.target

# /home/$user/.config/systemd/user/service.d/user-failure-notification.conf
[Unit]
OnFailure=user-failure-notification@%n
Andreas Vöst
Last edit
Andreas Vöst
License
Source code in this card is licensed under the MIT License.