updated haproxy state

This commit is contained in:
Paul 2022-10-10 10:16:32 +02:00
parent 1a2e8b109f
commit 0e36358ea8
5 changed files with 48 additions and 5 deletions

View File

@ -3,6 +3,8 @@ haproxy:
enabled: true
packages:
- haproxy
scripts:
- hello_world.lua
config:
defaults:
#log global:

View File

@ -2,4 +2,23 @@
{%- from "haproxy/map.jinja" import haproxy with context %}
haproxy-pkg:
pkg.installed:
- pkgs: {{ haproxy.packages }}
- pkgs: {{ haproxy.packages }}
haproxy-script-dir:
file.directory:
- name: {{ haproxy.config.dir }}/scripts
- user: {{ haproxy.config.user }}
- group: {{ haproxy.config.group }}
- mode: "0700"
{% for filename in haproxy.scripts %}
haprox-script-{{ filename }}:
file.managed:
- name: {{ haproxy.config.dir }}/scripts/{{ filename }}
- source: salt://haproxy/scripts/{{ filename }}
- user: {{ haproxy.config.user }}
- group: {{ haproxy.config.group }}
- mode: "0700"
- watch_in:
- service: haproxy-service
{% endfor %}

View File

@ -0,0 +1,11 @@
local args = table.pack(...)
core.register_service("hello-world", "http", function(applet)
local response = "Hello World !"
applet:set_status(200)
applet:add_header("content-length", string.len(response))
applet:add_header("content-type", "text/plain")
applet:start_response()
applet:send(response)
core.Info("test".."blabla")
end)

View File

@ -4,4 +4,4 @@ haproxy-service:
service.running:
- name: haproxy
- enable: true
- restart: true
- reload: true

View File

@ -35,7 +35,9 @@ listen stats
{%- endmacro %}
global
#lua-load /etc/haproxy/hello_world.lua
{%- for filename in haproxy.scripts %}
lua-load {{ haproxy.config.dir }}/scripts/{{ filename }}
{%- endfor %}
maxconn 1000
stats socket ipv4@127.0.0.1:9990 level admin
stats socket /var/run/hap-lb.sock mode 666 level admin
@ -53,9 +55,14 @@ defaults
{%- endfor %}
{%- if haproxy.config.admin %}
{{ admin() }}
{{ admin() }}
{%- endif %}
cache static
total-max-size 4095
max-object-size 50000
max-age 120
frontend http
bind *:80,:::80 v4v6
mode http
@ -75,6 +82,10 @@ backend {{ name }}
{%- if values.handle_head|default(false) %}
{{ handle_head() }}
{%- endif %}
{%- if values.usecache|default(true) %}
http-request cache-use static if { path_end .css .js .png .jpg }
http-response cache-store static
{%- endif %}
{%- if values.internal_access|default(false) %}
{{ internal_access() }}
{%- endif %}
@ -90,6 +101,6 @@ listen {{ name }}
{%- endif %}
default-server inter 3s fall 3
{%- for endpoint in values.endpoints %}
server {{ endpoint.name }} {{ endpoint.name }}:{{ endpoint.port }} check port {{ endpoint.port }}
server {{ endpoint.name }} {{ endpoint.name }}:{{ endpoint.port }} check {{ "backup" if endpoint.backup|default(false) }} port {{ endpoint.port }}
{%- endfor %}
{% endfor %}