consul-template v0.18.5 (9902dd5)
template = {
source = "haproxy.conf.ctmpl"
destination = "haproxy.conf"
command = "/usr/local/bin/haproxy -f /root/Documents/consulProto/haproxy.conf -sf $(pidof haproxy)"
}
global
maxconn 15
log 127.0.0.1 local1 notice
defaults
mode http
timeout connect 5000
timeout client 50000
timeout server 50000
listen http-in
bind *:8000{{range service "web"}}
server {{.Node}} {{.Address}}:{{.Port}}{{end}}
/usr/local/bin/haproxy -f /root/Documents/consulProto/haproxy.conf -sf $(pidof haproxy)
https://gist.github.com/thomas-oo/dcd2858a949340e50a5c2b1c1070a204
FYI: When I did this command manually and checking the exit code, it is indeed 0 as expected by consul-template
The command should have been run, which restarts a new haproxy process with the new conf file, and stops the old haproxy process.
It shows an improper usage message from haproxy, suggesting that the pidof command did not work (this is my guess). Thus the old haproxy process continues and is configured with the old conf file.
This is a known issue with haproxy. The first time that CT runs, pidof will return`(nothing), which haproxy interprets as a missing argument. You'll need to write a wrapper script to first check if haproxy is running and then conditionally use the-f` flag.
Found a quick workaround which is to pass the entire command into "/bin/bash -c '[problematic command]'". In my example, my command became "/bin/bash -c '/usr/local/bin/haproxy -f /root/Documents/consulProto/haproxy.conf -sf $(pidof haproxy) &'"
Not sure if this is useful but..
Most helpful comment
Found a quick workaround which is to pass the entire command into "/bin/bash -c '[problematic command]'". In my example, my command became
"/bin/bash -c '/usr/local/bin/haproxy -f /root/Documents/consulProto/haproxy.conf -sf $(pidof haproxy) &'"Not sure if this is useful but..