consul-template: multiple dependent templates

1,259 views
Skip to first unread message

Nicholas Capo

unread,
Mar 4, 2015, 12:21:59 PM3/4/15
to consu...@googlegroups.com
I will soon have three nginx configs that have templating for the same services [0]. (See consul-template config below)

I am concerned that these templates will run in serial, and for a short amount of time be inconsistent. In other words, nginx would be reloaded three times, each time with a slightly updated overall config.

Is there a way to avoid this? Are the commands defered until all templates are generated? Can I have multiple source and destination stanzas with a single command?

Nicholas


[0] I know, our setup is kinda complex, but not yet complicated: https://www.python.org/dev/peps/pep-0020/

-------------------------------------------------------------------------------



template {
  source = "/etc/consul-template/nginx/nginx.tmpl"
  destination = "/etc/nginx/sites-enabled/example.com"
  command = "sudo /etc/init.d/nginx reload"
}

template {
  source = "/etc/consul-template/nginx/localhost.tmpl"
  destination = "/etc/nginx/sites-enabled/localhost"
  command = "sudo /etc/init.d/nginx reload"
}

template {
  source = "/etc/consul-template/nginx/upstreams.tmpl"
  destination = "/etc/nginx/sites-enabled/upstreams"
  command = "sudo /etc/init.d/nginx reload"
}

Seth Vargo

unread,
Mar 4, 2015, 1:38:17 PM3/4/15
to Nicholas Capo, consu...@googlegroups.com
Hi Nicholas,

I believe you want to use the quiescence timers build into Consul Template. Essentially you can tell Consul Template to `-wait` for a minimum and maximum amount of time for data to become "stable", does that make sense? For example:

    consul-template -wait 10s

Tells CT to wait until no new data is returned from Consul for 10 seconds. Similarly:

    consul-template -wait 10s:100s

Tells CT to wait until no new data is returned from Consul for 10 seconds, but to force continuation after 100 seconds.

Best,
Seth

--
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicholas Capo

unread,
Mar 4, 2015, 2:24:35 PM3/4/15
to Seth Vargo, consu...@googlegroups.com
Good, then when the data is stable will it do the following?

1. generate template 1
  a. reload nginx
2. generate template 2
  a. reload nginx
3. generate template 3
  a. reload nginx

Or  will it:

1. generate template 1
2. generate template 2
3. generate template 3
4. reload nginx

Its the intermediate reloads that I'm worried about.

Nicholas


David Neudorfer

unread,
Jun 16, 2016, 2:17:24 PM6/16/16
to Consul, seth...@gmail.com
I'm looking for an answer to this as well.

Adam Greene

unread,
Aug 23, 2016, 10:50:01 PM8/23/16
to Consul, seth...@gmail.com
hey folks,

you may  have already figured this out, but if not, check out the new `exec` functionality in consul-template master (https://github.com/hashicorp/consul-template#exec-mode) .  I ran into the same issue and the exec functionality solved it for me.

Roberto Frutos

unread,
Sep 28, 2016, 1:09:05 PM9/28/16
to Consul, seth...@gmail.com
Will it be possible to use exec mode in backgroud in the future?
Why only foreground?

It'd be a really great approach if we can run command with exec mode in backgroud/foreground.

Seth Vargo

unread,
Sep 28, 2016, 1:10:18 PM9/28/16
to Roberto Frutos, Consul
If it runs in the background, it's no longer "exec", it would be a process supervisor and then Consul Template would be responsible for monitoring that process. How would it report back to the parent, etc? This is why you typically run CT under a processor monitor like init.d or upstart or systemd.

Best,
Seth
Reply all
Reply to author
Forward
0 new messages