From 8c9bd970e93064bfe49aae1e9fa72c112d4738ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 29 Jun 2021 15:42:17 +0200 Subject: =?UTF-8?q?=F0=9F=90=9B=20Add=20haproxy.cfg=20for=202.x=20versions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Build will check which one is installed and only enable the correct one. See also #711 --- .../filesystem/root/etc/haproxy/haproxy.1.x.cfg | 49 ++++++++++++++++++++++ .../filesystem/root/etc/haproxy/haproxy.2.x.cfg | 49 ++++++++++++++++++++++ .../octopi/filesystem/root/etc/haproxy/haproxy.cfg | 49 ---------------------- src/modules/octopi/start_chroot_script | 9 ++++ 4 files changed, 107 insertions(+), 49 deletions(-) create mode 100644 src/modules/octopi/filesystem/root/etc/haproxy/haproxy.1.x.cfg create mode 100644 src/modules/octopi/filesystem/root/etc/haproxy/haproxy.2.x.cfg delete mode 100644 src/modules/octopi/filesystem/root/etc/haproxy/haproxy.cfg diff --git a/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.1.x.cfg b/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.1.x.cfg new file mode 100644 index 0000000..443dd00 --- /dev/null +++ b/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.1.x.cfg @@ -0,0 +1,49 @@ +global + maxconn 4096 + user haproxy + group haproxy + log /dev/log local1 debug + tune.ssl.default-dh-param 2048 + +defaults + log global + mode http + compression algo gzip + option httplog + option dontlognull + retries 3 + option redispatch + option http-server-close + option forwardfor + maxconn 2000 + timeout connect 5s + timeout client 15min + timeout server 15min + +frontend public + bind :::80 v4v6 + bind :::443 v4v6 ssl crt /etc/ssl/snakeoil.pem + option forwardfor except 127.0.0.1 + use_backend webcam if { path_beg /webcam/ } + use_backend webcam_hls if { path_beg /hls/ } + use_backend webcam_hls if { path_beg /jpeg/ } + default_backend octoprint + +backend octoprint + acl needs_scheme req.hdr_cnt(X-Scheme) eq 0 + + reqrep ^([^\ :]*)\ /(.*) \1\ /\2 + reqadd X-Scheme:\ https if needs_scheme { ssl_fc } + reqadd X-Scheme:\ http if needs_scheme !{ ssl_fc } + option forwardfor + server octoprint1 127.0.0.1:5000 + errorfile 503 /etc/haproxy/errors/503-no-octoprint.http + +backend webcam + reqrep ^([^\ :]*)\ /webcam/(.*) \1\ /\2 + server webcam1 127.0.0.1:8080 + errorfile 503 /etc/haproxy/errors/503-no-webcam.http + +backend webcam_hls + server webcam_hls_1 127.0.0.1:28126 + errorfile 503 /etc/haproxy/errors/503-no-webcam-hls.http diff --git a/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.2.x.cfg b/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.2.x.cfg new file mode 100644 index 0000000..8ef4d16 --- /dev/null +++ b/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.2.x.cfg @@ -0,0 +1,49 @@ +global + maxconn 4096 + user haproxy + group haproxy + log /dev/log local1 debug + tune.ssl.default-dh-param 2048 + +defaults + log global + mode http + compression algo gzip + option httplog + option dontlognull + retries 3 + option redispatch + option http-server-close + option forwardfor + maxconn 2000 + timeout connect 5s + timeout client 15min + timeout server 15min + +frontend public + bind :::80 v4v6 + bind :::443 v4v6 ssl crt /etc/ssl/snakeoil.pem + option forwardfor except 127.0.0.1 + use_backend webcam if { path_beg /webcam/ } + use_backend webcam_hls if { path_beg /hls/ } + use_backend webcam_hls if { path_beg /jpeg/ } + default_backend octoprint + +backend octoprint + acl needs_scheme req.hdr_cnt(X-Scheme) eq 0 + + http-request replace-path ^([^\ :]*)\ /(.*) \1\ /\2 + http-request add-header X-Scheme https if needs_scheme { ssl_fc } + http-request add-header X-Scheme http if needs_scheme !{ ssl_fc } + option forwardfor + server octoprint1 127.0.0.1:5000 + errorfile 503 /etc/haproxy/errors/503-no-octoprint.http + +backend webcam + http-request replace-path /webcam/(.*) /\1 + server webcam1 127.0.0.1:8080 + errorfile 503 /etc/haproxy/errors/503-no-webcam.http + +backend webcam_hls + server webcam_hls_1 127.0.0.1:28126 + errorfile 503 /etc/haproxy/errors/503-no-webcam-hls.http diff --git a/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.cfg b/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.cfg deleted file mode 100644 index 443dd00..0000000 --- a/src/modules/octopi/filesystem/root/etc/haproxy/haproxy.cfg +++ /dev/null @@ -1,49 +0,0 @@ -global - maxconn 4096 - user haproxy - group haproxy - log /dev/log local1 debug - tune.ssl.default-dh-param 2048 - -defaults - log global - mode http - compression algo gzip - option httplog - option dontlognull - retries 3 - option redispatch - option http-server-close - option forwardfor - maxconn 2000 - timeout connect 5s - timeout client 15min - timeout server 15min - -frontend public - bind :::80 v4v6 - bind :::443 v4v6 ssl crt /etc/ssl/snakeoil.pem - option forwardfor except 127.0.0.1 - use_backend webcam if { path_beg /webcam/ } - use_backend webcam_hls if { path_beg /hls/ } - use_backend webcam_hls if { path_beg /jpeg/ } - default_backend octoprint - -backend octoprint - acl needs_scheme req.hdr_cnt(X-Scheme) eq 0 - - reqrep ^([^\ :]*)\ /(.*) \1\ /\2 - reqadd X-Scheme:\ https if needs_scheme { ssl_fc } - reqadd X-Scheme:\ http if needs_scheme !{ ssl_fc } - option forwardfor - server octoprint1 127.0.0.1:5000 - errorfile 503 /etc/haproxy/errors/503-no-octoprint.http - -backend webcam - reqrep ^([^\ :]*)\ /webcam/(.*) \1\ /\2 - server webcam1 127.0.0.1:8080 - errorfile 503 /etc/haproxy/errors/503-no-webcam.http - -backend webcam_hls - server webcam_hls_1 127.0.0.1:28126 - errorfile 503 /etc/haproxy/errors/503-no-webcam-hls.http diff --git a/src/modules/octopi/start_chroot_script b/src/modules/octopi/start_chroot_script index 38d3f69..1b905a8 100755 --- a/src/modules/octopi/start_chroot_script +++ b/src/modules/octopi/start_chroot_script @@ -227,6 +227,15 @@ fi if [ "$OCTOPI_INCLUDE_HAPROXY" == "yes" ] then systemctl_if_exists enable gencert.service + + haproxy_version=$(dpkg -s haproxy | grep '^Version:' | awk '{print $2}') + if [[ $haproxy_version = 2.* ]]; then + mv /etc/haproxy/haproxy.2.x.cfg /etc/haproxy/haproxy.cfg + rm /etc/haproxy/haproxy.1.x.cfg + else + mv /etc/haproxy/haproxy.1.x.cfg /etc/haproxy/haproxy.cfg + rm /etc/haproxy/haproxy.2.x.cfg + fi else # let's remove the configs for system services we don't need rm /etc/systemd/system/gencert.service -- cgit v1.2.3