1

Say I have a unit foo.service that I want run after bar.service exits (with any status, whether success or failure). I do not think that After= or Before= will help me here. How can I accomplish this within systemd and not in the script launched by systemd?

For context, in my environment, say bar.service fails and has a line OnFailure=foo.service to force foo.service to fix problems and then launch bar.service again.

1 Answer 1

1

You can (probably) use ExecStopPost=

Additional commands that are executed after the service is stopped. This includes cases where the commands configured in ExecStop= were used, where the service does not have any ExecStop= defined, or where the service exited unexpectedly. This argument takes multiple command lines, following the same scheme as described for ExecStart=. Use of these settings is optional. Specifier and environment variable substitution is supported. Note that – unlike ExecStop= – commands specified with this setting are invoked when a service failed to start up correctly and is shut down again.

It is recommended to use this setting for clean-up operations that shall be executed even when the service failed to start up correctly. Commands configured with this setting need to be able to operate even if the service failed starting up half-way and left incompletely initialized data around. As the service's processes have been terminated already when the commands specified with this setting are executed they should not attempt to communicate with them.

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, see systemd.exec(5) for details.

3
  • I'll try it.... Commented May 16, 2019 at 17:10
  • Doesn't appear to work. I had it call a script and I cannot see any evidence that it ran. Commented May 16, 2019 at 18:35
  • I take it back, I forgot a daemon-reload. Commented May 16, 2019 at 19:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.