Execute one command for multiple templates in consul-template

I have more than one configuration file for a service. I need to reload the service only once if either (or both) of the configuration files change. Is there a way to do this? Rapidly reloading the services on each template render has a bad effect on performance.

I thought, maybe I should only define the command on one of the templates, render the data that would go into the other template in a comment so it ensures a reload, but can I be sure about the order in which the templates finish rendering?

Hey Gargron,

You should be able to achieve what you are after by configuring your consul-template to have your service run as the child/exec’d process (see the exec {} block in the config). This process gets reloaded whenever any template has changed. To keep the service from reloading too much if the monitored data is flapping you can set it up to wait a certain amount of time after each update before rendering the template and reloading the process. See the wait {} block inside template for more on this.

2 Likes