Florian Heinle
9 months
Claus-Theodor Riegg
8 years
Kim Klotz
11 months
Moritz Kraus
1 year
Claus-Theodor Riegg
1 year
Stefan Xenopol
1 year

Desktop notification for failed systemd user services

Posted Over 1 year ago. 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
Over 1 year ago
Andreas Vöst
License
Source code in this card is licensed under the MIT License.