[systemd-devel] Skip ExecStop after service end or failure

Lennart Poettering lennart at poettering.net
Sun Dec 20 12:00:38 UTC 2020


On So, 20.12.20 12:48, Robert Dahlem (Robert.Dahlem at gmx.net) wrote:

> Hi,
>
> is there a way to NOT run ExecStop, when a service started successfully,
> but ends later without being stopped?
>
> My scenario: I have an ExecStop that should only run after
>
> 	systemctl stop XXX.service
>
> which means: only when someone administratively shuts down the service.
>
> It must not run, when the service terminates by whatever means (exit 0,
> exit 1, signal). In this case, systemd shall just mark the service as
> failed and leave it be.
>
> Can this be configured?

No, it cannot.

But you can use $EXIT_CODE, $EXIT_STATUS and $SERVICE_RESULT env vars
in ExecStop= that tell you what happened. Thus you can write a script
wrapping your stop command that determines what to do.

Further details on these env vars are on systemd.exec(5).

Lennart

--
Lennart Poettering, Berlin


More information about the systemd-devel mailing list