Hi folks,
I have the task, which runs DB instance and has the template to ended pg_hba.conf file so that instances can talk to each other via services addresses, published to Consul. It looks something like this
...
service {
name = "worker-${NOMAD_ALLOC_INDEX}"
port = "psql"
}
...
template {
data = <<EOF
{{- range services }}
{{- range service .Name }}
host all root {{ .Address }}/32 trust
{{- end }}
{{- end }}
Now the issue I have with it is that it constantly restarts after start. In allocation events I can see messages again and again:
2022-08-08T11:17:53+03:00 Started Task started by client
2022-08-08T11:17:53+03:00 Restarting Task restarting in 0s
2022-08-08T11:17:53+03:00 Terminated Exit Code: 137, Exit Message: "Docker container exited with non-zero exit code: 137"
2022-08-08T11:17:48+03:00 Restart Signaled Template with change_mode restart re-rendered
2022-08-08T11:17:47+03:00 Started Task started by client
How I see this issue:
- Task starts and publishes service to Consul
- Template engine sees new service in consul so it triggers template update and restarts task
- While the task restarts, service gets unpublished from Consul
- Template engine sees the list of services updated (service got removed) and triggers template rerender → task restart
- While the task restarts service from the previous run gets published into Consul and when the task starts again it sees this update and starts this whole thing again and again.
As a result, I have the task restarting every ~5s