Disons que j'ai une unité foo.serviceque je veux exécuter après les bar.servicesorties (avec n'importe quel statut, qu'il s'agisse d'un succès ou d'un échec). Je ne pense pas que After=ou Before=va m'aider ici. Comment puis-je accomplir cela dans systemd et non dans le script lancé par systemd ?

Pour le contexte, dans mon environnement, disons bar.serviceéchoue et a une ligne OnFailure=foo.serviceà forcer foo.servicepour résoudre les problèmes, puis relancer bar.service.


Vous pouvez (probablement) utiliser 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.