[systemd-devel] directive for executing a script on service failure

Mantas Mikulėnas grawity at gmail.com
Fri Feb 6 11:23:14 PST 2015


On Fri, Feb 6, 2015 at 5:26 PM, George Karakougioumtzis <
mad-proffessor at hotmail.com> wrote:

> Hi. Congrats for the near perfect job on systemd! I was searching for a
> directive to execute a script upon systemd service failure. I would like
> to receive desktop notifications about such  failures. I stumbled upon
> OnFailure and FailureAction but these have hardcoded list of actions?
>

One of those actions is "start an arbitrary unit", which could handle
notifications... Unfortunately it doesn't actually pass any failure
information to that unit. So, instead, you might have to watch the system
log (journal) for unit failure notices. (I would normally have said that
the journal makes it easy to filter for them, but quite strangely, these
ones don't have a MESSAGE_ID attached...)

Maybe others will have better suggestions.


> Any hints how to get notified (with notify-send most likely)?


systemd calling notify-send isn't going to happen – as a service, it runs
"outside" your desktop session, and has no access to its D-Bus session bus,
which tends to be started at a random address. (There might even be several
sessions, not just one!) And even considering the future "user bus" plans
(which would put the session bus at a known fixed location), the whole idea
of having a service inject something into a desktop session is really ugly.
Even Microsoft realized that and implemented "session 0 isolation" in VIsta.

In other words, such a notifier would need to be started from within your
desktop session, connect *to* systemd (either by waiting for signals on the
system bus or by watching the journal messages), and idle in background
waiting for some unit to fail. With DBus it could be a simple 10-line
script, waiting for signals on one bus and calling Notify() on another...

-- 
Mantas Mikulėnas <grawity at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150206/4ec0259c/attachment.html>


More information about the systemd-devel mailing list