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 enabled: true
packages: packages:
- haproxy - haproxy
scripts:
- hello_world.lua
config: config:
defaults: defaults:
#log global: #log global:

View File

@ -3,3 +3,22 @@
haproxy-pkg: haproxy-pkg:
pkg.installed: 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: service.running:
- name: haproxy - name: haproxy
- enable: true - enable: true
- restart: true - reload: true

View File

@ -35,7 +35,9 @@ listen stats
{%- endmacro %} {%- endmacro %}
global global
#lua-load /etc/haproxy/hello_world.lua {%- for filename in haproxy.scripts %}
lua-load {{ haproxy.config.dir }}/scripts/{{ filename }}
{%- endfor %}
maxconn 1000 maxconn 1000
stats socket ipv4@127.0.0.1:9990 level admin stats socket ipv4@127.0.0.1:9990 level admin
stats socket /var/run/hap-lb.sock mode 666 level admin stats socket /var/run/hap-lb.sock mode 666 level admin
@ -56,6 +58,11 @@ defaults
{{ admin() }} {{ admin() }}
{%- endif %} {%- endif %}
cache static
total-max-size 4095
max-object-size 50000
max-age 120
frontend http frontend http
bind *:80,:::80 v4v6 bind *:80,:::80 v4v6
mode http mode http
@ -75,6 +82,10 @@ backend {{ name }}
{%- if values.handle_head|default(false) %} {%- if values.handle_head|default(false) %}
{{ handle_head() }} {{ handle_head() }}
{%- endif %} {%- 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) %} {%- if values.internal_access|default(false) %}
{{ internal_access() }} {{ internal_access() }}
{%- endif %} {%- endif %}
@ -90,6 +101,6 @@ listen {{ name }}
{%- endif %} {%- endif %}
default-server inter 3s fall 3 default-server inter 3s fall 3
{%- for endpoint in values.endpoints %} {%- 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 %}
{% endfor %} {% endfor %}