haproxy-lb/pkg/haproxy/template.go
2021-04-10 02:42:55 +02:00

55 lines
1.3 KiB
Go

package haproxy
const haproxyConfigTemplate = `global
daemon
# TODO
#chroot /var/lib/haproxy
chroot /usr/share/haproxy
pidfile /run/haproxy.pid
user haproxy
group haproxy
maxconn 20000
defaults
mode tcp
log global
retries 2
timeout connect 3000ms
timeout server 5000ms
timeout client 5000ms
timeout tunnel 3600s
timeout check 10s
frontend stats
mode http
bind 127.0.0.1:8404
stats enable
stats uri /stats
stats refresh 10s
stats admin if LOCALHOST
{{ range $item := .LoadBalancers -}}
{{ range $port := $item.Ports -}}
frontend fr_{{ $item.Name }}_{{ $port.Port }}
bind {{ $item.IP }}:{{ $port.Port }}
{{- range $opt := $item.Options.Frontend }}
option {{ $opt }}
{{- end }}
default_backend ba_{{ $item.Name }}_{{ $port.Port }}
backend ba_{{ $item.Name }}_{{ $port.Port }}
balance roundrobin
{{- range $opt := $item.Options.Backend }}
option {{ $opt }}
{{- end }}
default-server inter 3s downinter 10s fall 2 rise 2 on-marked-down shutdown-sessions {{ $item.Options.DefaultServer }}
{{- if eq $item.Options.ProxyProtocol "v1" }}
send-proxy
{{- else if eq $item.Options.ProxyProtocol "v2" }}
send-proxy-v2
{{- end }}
{{- if $item.Options.CheckProxyProtocol }}
check-send-proxy
{{- end }}
{{- range $srv := $port.Servers }}
server {{ $srv.Name }} {{ $srv.IP }}:{{ $srv.Port }} check
{{- end }}
{{ end -}}
{{ end -}}
`