[Unit]
Description=Run Consul-template to watch haproxy config updates

[Service]
{%- if consul.tokens.haproxy is defined %}
Environment="CONSUL_HTTP_TOKEN={{ consul.tokens.haproxy }}"
{%- endif %}

{%- if vault.tokens.haproxy is defined %}
Environment="VAULT_TOKEN={{ vault.tokens.haproxy }}"
{%- endif %}

Environment="CONSUL_HTTP_ADDR=https://127.0.0.1:€# lookup('env','CONSUL_HTTPS_PORT') | default(8501, true) | int #€"
Environment="CONSUL_CACERT=€# layerops_tls_ca_file #€"
Environment="VAULT_CACERT=€# layerops_tls_ca_file #€"

TimeoutStartSec=0
ExecStart=€# local_bin_path #€/consul-template \
  -default-left-delimiter '{€' \
  -default-right-delimiter '€}' \
  -template="€# haproxy_config_path #€/haproxy.cfg.tmpl:€# haproxy_config_path #€/haproxy.cfg:€# local_bin_path #€/haproxy_reload"
ExecStop=/bin/kill -9 $MAINPID

Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
