updated haproxy state

This commit is contained in:
Paul 2022-11-13 20:48:27 +01:00
parent 954e8cf7bf
commit 039abe0b52
2 changed files with 24 additions and 15 deletions

View File

@ -28,6 +28,8 @@ haproxy:
timeout connect: 4s timeout connect: 4s
timeout server: 30m timeout server: 30m
timeout check: 5s timeout check: 5s
balance: roundrobin
check: True
dir: /etc/haproxy dir: /etc/haproxy
configfile: haproxy.cfg configfile: haproxy.cfg
user: haproxy user: haproxy
@ -65,7 +67,7 @@ haproxy:
- text/plain - text/plain
- text/css - text/css
- text/javascript - text/javascript
- application/javascript - application/json
cache_file_types: cache_file_types:
- .css - .css
- .js - .js

View File

@ -14,9 +14,18 @@
http-response set-header server "{{ haproxy.config.servername }}" http-response set-header server "{{ haproxy.config.servername }}"
{%- endmacro -%} {%- endmacro -%}
{%- macro endpoints(servers, check, ssl) -%} {%- macro httpcheckrules(layer="layer7",inter="2s",fall=5,rise=5) -%}check observe {{ layer }} inter {{ inter }} fall {{ fall }} rise {{ rise }}{%- endmacro -%}
{%- macro httpsslrules() -%}ssl verify none{%- endmacro -%}
{%- macro httpendpoints(servers=[], check=True, ssl=False) -%}
{%- for server in servers %} {%- for server in servers %}
server {{ server.name }} {{ server.name }}:{{ server.port }}{{ " check observe layer7 inter 2s fall 5 rise 5 " if check|default(true) }}{{ " ssl verify none " if ssl|default(false) }} server {{ server.name }} {{ server.name }}:{{ server.port }}{{ " " + httpcheckrules() if check }}{{ " " + httpsslrules() if ssl }}
{%- endfor %}
{%- endmacro -%}
{%- macro tcpendpoints(servers=[], check=True) -%}
{%- for server in servers %}
server {{ server.name }} {{ server.name }}:{{ server.port }}{{ " check" if check }}{{ " backup" if server.backup|default(False) }} port {{ server.port }}
{%- endfor %} {%- endfor %}
{%- endmacro -%} {%- endmacro -%}
@ -116,37 +125,37 @@ frontend https
# HTTP Backends # HTTP Backends
{% for name, values in haproxy.config.vhosts.items() %} {% for name, values in haproxy.config.vhosts.items() %}
{%- if not values.redirect|default(false) %} {%- if not values.redirect|default(False) %}
backend {{ name }} backend {{ name }}
balance {{ values.balance|default("roundrobin") }} balance {{ values.balance|default(haproxy.config.balance) }}
mode http mode http
option forwardfor option forwardfor
{%- if values.check|default(false) %} {%- if values.check|default(haproxy.config.check) %}
option httpchk option httpchk
{%- for step in values.check_steps|default([]) %} {%- for step in values.check_steps|default([]) %}
http-check {{ step }} http-check {{ step }}
{%- endfor %} {%- endfor %}
{%- endif %} {%- endif %}
{%- if values.head|default(false) %} {%- if values.head|default(False) %}
{{ head() }} {{ head() }}
{%- endif %} {%- endif %}
{%- if values.compression|default(true) %} {%- if values.compression|default(True) %}
{{ compression() }} {{ compression() }}
{%- endif %} {%- endif %}
{%- if values.usecache|default(true) %} {%- if values.usecache|default(True) %}
{{ cache() }} {{ cache() }}
{%- endif %} {%- endif %}
{%- if values.serverheader|default(true) %} {%- if values.serverheader|default(True) %}
{{ serverheader() }} {{ serverheader() }}
{%- endif %} {%- endif %}
{%- if values.internal|default(false) %} {%- if values.internal|default(False) %}
{{ internal() }} {{ internal() }}
{%- endif %} {%- endif %}
{{- endpoints(values.servers, values.check, values.ssl) }} {{- httpendpoints(servers=values.servers, check=values.check|default(haproxy.config.check), ssl=values.ssl|default(False)) }}
{%- endif %} {%- endif %}
{% endfor %} {% endfor %}
@ -160,7 +169,5 @@ listen {{ name }}
option pgsql-check user postgres option pgsql-check user postgres
{%- endif %} {%- endif %}
default-server inter 3s fall 3 default-server inter 3s fall 3
{%- for server in values.servers %} {{- tcpendpoints(servers=values.servers, check=values.check|default(haproxy.config.check)) }}
server {{ server.name }} {{ server.name }}:{{ server.port }} check {{ "backup" if server.backup|default(false) }} port {{ server.port }}
{%- endfor %}
{% endfor -%} {% endfor -%}