[systemd-devel] How to manually set service in "failed" state

Lennart Poettering lennart at poettering.net
Mon Mar 24 12:35:55 PDT 2014


On Tue, 18.03.14 14:59, Usman (desert03 at yahoo.com) wrote:

> Hi Guys,
> 
> I am trying to test some code with respect to my services setup. I have two services, lets say service_a and service_b. In service_a unit file I have this:
> 
> OnFailure=service_b
> 
> 
> And from the man page for OnFailure unit I get this:
> 
> A space-separated list of one or more units that are activated when this unit enters the "failed" state
> 
> My question is, to test this setup, how can I have service_a in a
> "failed" state? I have tried using kill -9, but that leaves service in
> "signal" state and not "failed" state. How can I manually set a
> service in "failed" state so that service_b gets started for my
> testing? Any specific signal? Any help much appreciated.

kill -9 should work fine for this. Note that before entering "failed"
state the normal shutdown logic of a service is still executed. There is
no "signal" state btw, only a "signal" result code, which is
different. The state tells you the general fact that something failed,
the result will state you why it did that: due to non-zero exit code,
due to coredump, due to signal, due to watchdog timeout, due to lack of
resources, due to startup timeout, due to restart limit.

Also note that services that are configured for restart do not enter a
failed state, but only "restarting" state. Only after they hit the
restart limit they will be put in a failed state.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list