You are not logged in.

#1 2022-12-06 17:56:24

Galicarnax
Member
Registered: 2020-05-03
Posts: 17

systemd: getting notified of the degraded status

I know how to get notified when some particular unit fails. But what if I need to monitor the status of the entire system? Putting OnFailure= into each and every unit file is not an option, of course. Yet, I didn't find anything about systemd that could trigger an action on the failuer of any unit. For sure, I can make up a script that checks systemctl status every minute or so, but doesn't systemd provide a cleaner solution similar to OnFailure for individual units?

Last edited by Galicarnax (2022-12-06 17:58:57)

Offline

#2 2022-12-06 18:47:10

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 1,905
Website

Re: systemd: getting notified of the degraded status

Not tested: But you could group all desired services in a target and then monitor that target unit.

Offline

#3 2022-12-07 06:19:41

Galicarnax
Member
Registered: 2020-05-03
Posts: 17

Re: systemd: getting notified of the degraded status

schard wrote:

Not tested: But you could group all desired services in a target and then monitor that target unit.

As far as I understand, that still would require keeping the list of all desired services (and by the way, I'm interested not only in failed services but other units such as mounts as well).
E.g., if I add another unit, I would have to remeber to add it to the list. Not a big improvement over adding OnFailure= to all units smile

Offline

#4 2022-12-07 06:30:43

mpan
Member
Registered: 2012-08-01
Posts: 1,167
Website

Re: systemd: getting notified of the degraded status

Depending on whether there are failed units or not, this returns a success or a failure status code:

systectl status --failed &>/dev/null

or

systemctl is-failed --quiet '*'

You may put that in a timer and produce notifications upon a positive detection.


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

Board footer

Powered by FluxBB