[systemd-devel] Main process exit status variables not being sent to ExecStopPost= script

ithinki cant ithinkicant at hotmail.com
Thu Apr 6 20:55:05 UTC 2017


Hey folks,

I'm doing the following in my service unit file:
    ExecStopPost=/bin/myscript.sh

And in myscript.sh,
    #!/bin/bash
    echo $EXIT_STATUS >> /tmp/somefile

Yet when my service restarts (or I force crash it), an empty line is all that is written out (ie: the environment variable is unset). $SERVICE_RESULT and $EXIT_CODE are also empty.

I've also tried using the var in the unit file, eg: ExecStopPost=/bin/echo $EXIT_STATUS blahblah, but all I see in my service journal logs on service restart or crash is "blahblah".

Per systemd documentation, for ExecStopPost=, some environment variables are supposed to be set for the executed script/binary:

"Note that all commands that are configured with this setting are invoked with the result code of the service, as well as the main process' exit code and status, set in the $SERVICE_RESULT, $EXIT_CODE and $EXIT_STATUS environment variables"


I'm using systemd-231-2 on CentOS7, kernel 4.6.7

Am I doing something wrong?

Thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20170406/e30ec880/attachment.html>


More information about the systemd-devel mailing list