Is there a way to run a configtest utility (e.g. apache2ctl -t) before trying to restart a service when one of its configuration files changed?
Use case here is that I want to be resilient against configuration errors in an apache config (because apache just stops when it sees the config error, leaving me with a stopped apache)
You can use a
require => Exec[]
and daisy chain theexec
to require the config change(s).If the Exec fails (exit status != 0) the subsequent tasks that require it should fail as well. I do something similar to execute ssh-keygen then set special permissions on .ssh when creating new users.
Example: