Discussion:
Conditional clean up action
(too old to reply)
Mircea Husz
2018-01-04 20:50:39 UTC
Permalink
Raw Message
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 ?
-Mike
Michal Sekletar
2018-01-05 08:55:04 UTC
Permalink
Raw Message
Post by Mircea Husz
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
?
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
Mircea Husz
2018-01-05 19:04:52 UTC
Permalink
Raw Message
Post by Michal Sekletar
Post by Mircea Husz
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
?
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
Thank you, you're getting me on the right path. I found that
ExecMainCode returned 1 when the process
was brought down gracefully, but in the process (no pun intended) of
testing I discovered ExecMainStatus.
Its value is 0 on normal termination, and non-zero when I cause it to
crash. However this might be all
coincidental and don't want to infer what the properties mean based on
these observations.

They do seem to mirror the values listed in systemd status output, as
in: (code=exited, status=0/SUCCESS)

I'd like to find documentation on these properties and didn't find any;
can you point me in the right direction?
I searched the github repo, stumbled upon run_context_update
https://github.com/systemd/systemd/blob/32827740505dab1b7138b3a51a545cd
4191b8265/src/run/run.c
which to the untrained eye seems to say that ExecMainCode is the
exit_code and ExecMainStatus is the exit_status
However the values don't match https://www.freedesktop.org/software/sys
temd/man/systemd.exec.html#%24EXIT_CODE

ExecMainStatus might be the return status of the process, but I'd like
to find some documentation that confirms it.
-Mike
Lennart Poettering
2018-01-08 19:01:19 UTC
Permalink
Raw Message
Post by Mircea Husz
Post by Michal Sekletar
Post by Mircea Husz
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
?
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
Thank you, you're getting me on the right path. I found that
ExecMainCode returned 1 when the process
was brought down gracefully, but in the process (no pun intended) of
testing I discovered ExecMainStatus.
Its value is 0 on normal termination, and non-zero when I cause it to
crash. However this might be all
coincidental and don't want to infer what the properties mean based on
these observations.
They do seem to mirror the values listed in systemd status output, as
in: (code=exited, status=0/SUCCESS)
I'd like to find documentation on these properties and didn't find any;
can you point me in the right direction?
You may find (not very up-to-date) docs about those properties here:

https://www.freedesktop.org/wiki/Software/systemd/dbus/

Lennart
--
Lennart Poettering, Red Hat
Mircea Husz
2018-01-08 20:21:30 UTC
Permalink
Raw Message
Post by Lennart Poettering
Post by Mircea Husz
Post by Michal Sekletar
Post by Mircea Husz
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
?
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
Thank you, you're getting me on the right path. I found that
ExecMainCode returned 1 when the process
was brought down gracefully, but in the process (no pun intended) of
testing I discovered ExecMainStatus.
Its value is 0 on normal termination, and non-zero when I cause it to
crash. However this might be all
coincidental and don't want to infer what the properties mean based on
these observations.
They do seem to mirror the values listed in systemd status output, as
in: (code=exited, status=0/SUCCESS)
I'd like to find documentation on these properties and didn't find any;
can you point me in the right direction?
https://www.freedesktop.org/wiki/Software/systemd/dbus/
Lennart
Thank you
-Mike

Loading...