hashicorp / consul-template

Template rendering, notifier, and supervisor for @HashiCorp Consul and Vault data.
https://www.hashicorp.com/
Mozilla Public License 2.0
4.76k stars 781 forks source link

Blank rendered file after service restart #1713

Closed oliverprt closed 1 year ago

oliverprt commented 1 year ago

Consul Template version

0.30.0 This did also happen with version 0.25.0

Consul version

1.12.9

Consul Template Configuration

consul {
  address = "127.0.0.1:8500"
  token = "xxxxxxxxx"
    retry {

    enabled = true
    attempts = 12
    backoff = "250ms"
    max_backoff = "1m"
  }

ssl {

    enabled = false
    verify = true
  }
}

reload_signal = "SIGHUP"
kill_signal = "SIGINT"
log_level = "err"
pid_file = "/var/run/consul-template/consul-template.pid"
wait {
  min = "5s"
  max = "10s"
}

template {
  source = "/etc/consul-template/templates/serviceidentity_app01-2019052800.tpl"
  destination = "/app_deployment/app01/central/dbaccess/serveridentity.txt"
  create_dest_dirs = true
  command = "bash -c 'if id -u majandust > /dev/null 2>&1; then chown majandust:root /app_deployment/app01/central/dbaccess/serveridentity.txt; fi'"
  command_timeout = "60s"
  error_on_missing_key = false
  perms = 0644
  backup = true
  wait {
    min = "2s"
    max = "10s"
  }
}
{{ with node }}{{ range services }}{{ $name := .Name }}{{ $service := service (printf "%s|any" $name) }}{{ range $service }}{{ if eq node.Node.Node .Node }}{{ $ews_instance := index .ServiceMeta "ews_instance" }}{{ if eq $ews_instance "app01" }}{{ index .ServiceMeta "serveridentity" }}{{ end }}{{ end }}{{ end }}{{ end }}{{ end -}}
au.domain.com

Command

"bash -c 'if id -u majandust > /dev/null 2>&1; then chown majandust:root /app_deployment/app01/central/dbaccess/serveridentity.txt; fi'"

Expected behavior

Consul should render configuration file based on data from Consul Service meta keys.

Actual behavior

After consul or consul-template service restart, destination configuration file is blank until the configured minimum wait time for template kicks in.

Not sure if this is Consul or Consul Template issue, because it happens after restart of any of these two service.

oliverprt commented 1 year ago

I think this can be closed because after further troubleshooting I believe the problem is with the Consul service itself: https://github.com/hashicorp/consul/issues/16539