<html><head></head><body><div>On Fri, 2018-01-05 at 09:55 +0100, Michal Sekletar wrote:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>On Thu, Jan 4, 2018 at 9:50 PM, Mircea Husz <<a href="mailto:mirceahusz@yahoo.com">mirceahusz@yahoo.com</a>> wrote:
<blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex">
Migrating an init script to systemd, and need to archive logs only if the
service exited normally with a return code 0. I found $SERVICE_RESULT,
$EXIT_CODE, and $EXIT_STATUS but they are in a newer version of systemd, I
am stuck with version 219 on CentOS 7.
I'd love to run ExecStopPost on a conditional exit status but that's just
not available. Before I get creative with Pre, Start, and Post bash scripts,
is there any straightforward way of handling this kind of thing with systemd
?
</blockquote>
You could query the exit code in post script via systemctl show, the
property is called ExecMainCode. Btw, in case you have RH subscription
then please open a support case and we can backport this functionality
to RHEL/CentOS.
Cheers,
Michal<font face="monospace" size="3"></font>
</pre></blockquote><div><br></div><div>Thank you, you're getting me on the right path. I found that ExecMainCode returned 1 when the process</div><div> was brought down gracefully, but in the process (no pun intended) of testing I discovered ExecMainStatus. </div><div>Its value is 0 on normal termination, and non-zero when I cause it to crash. However this might be all </div><div>coincidental and don't want to infer what the properties mean based on these observations.</div><div><br></div><div>They do seem to mirror the values listed in systemd status output, as in: (code=exited, status=0/SUCCESS)</div><div><br></div><div>I'd like to find documentation on these properties and didn't find any; can you point me in the right direction?</div><div>I searched the github repo, stumbled upon run_context_update </div><div><a href="https://github.com/systemd/systemd/blob/32827740505dab1b7138b3a51a545cd4191b8265/src/run/run.c">https://github.com/systemd/systemd/blob/32827740505dab1b7138b3a51a545cd4191b8265/src/run/run.c</a></div><div>which to the untrained eye seems to say that ExecMainCode is the exit_code and ExecMainStatus is the exit_status</div><div>However the values don't match <a href="https://www.freedesktop.org/software/systemd/man/systemd.exec.html#%24EXIT_CODE">https://www.freedesktop.org/software/systemd/man/systemd.exec.html#%24EXIT_CODE</a></div><div><br></div><div>ExecMainStatus might be the return status of the process, but I'd like to find some documentation that confirms it. </div><div><br></div><div>-Mike</div><div><br></div></body></html>