Which is the proper way to use onfailure in systemd-Unix?

Which is the proper way to use onfailure in systemd-Unix?

In the code you run at ExecStopPost=, you can use one of $SERVICE_RESULT, $EXIT_CODE or $EXIT_STATUS to determine the failure condition and act accordingly. See the documentation on those environment variables to check which one is appropriate for you. Then you can use Restart=on-failure so that systemd tries to restart your unit when it fails.

What does restart = on-abnormal do in systemd?

Restart=on-abnormal From the documentation ( systemd.service and systemd.service ), I’d expect that if I kill foo_app in a way such that Restart=on-abnormal is triggered (e.g. killall -9 foo_app ), systemd should give priority to Restart=on-abnormal over OnFailure=systemd-reboot.service and not start systemd-reboot.service.

When does systemd set the state to failed?

Currently systemd sets the state to failed after every attempted start, regardless of whether the start limit has been reached. In the issue the OP wrote an amusing anecdote about learning to ride a bike that I highly suggest taking a gander at. Thanks for contributing an answer to Unix & Linux Stack Exchange!

Is there a fix for systemd V239 yet?

Edit 2019/08/12: Per therealjumbo ‘s comment, the fix for this has been merged and released with systemd v239, thus, if you aren’t pinned to a version due to your distribution (looking at you CentOS) update and make merry!

When does a service restart in systemd-systemctl?

If set to on-failure, the service will be restarted when the process exits with a non-zero exit code, is terminated by a signal (including on core dump, but excluding the aforementioned four signals), when an operation (such as service reload) times out, and when the configured watchdog timeout is triggered. […]

When does a service restart it enters a failed state?

[snip] Note that service restart is subject to unit start rate limiting configured with StartLimitIntervalSec= and StartLimitBurst=, see systemd.unit (5) for details. A restarted service enters the failed state only after the start limits are reached.

How to run systemd service as specific user?

Can the service use a domain user instead of the local user when running. Our client machine is redhat linux on which tomcat is running as a service. Now how can we run the tomcat as the same domain user that has access to the MSSQL DB ? You can just place the username in the User=USERNAME field without any domain details.

When does a service unit enter the failed state?

OnFailure=. A space-separated list of one or more units that are activated when this unit enters the “failed” state. A service unit using Restart= enters the failed state only after the start limits are reached.

When does foo.service enter the failed state?

What’s unusual is that systemd prints foo.service: Unit entered failed state. whenever foo_app is killed, even if it is about to be restarted through Restart=on-abnormal. This seems to directly contradict these lines from the docs quoted above: A service unit using Restart= enters the failed state only after the start limits are reached.