From 1d0f9d4cb9c251940b183904eb5dc4d4b6120569 Mon Sep 17 00:00:00 2001 From: paukstelis Date: Wed, 25 May 2022 12:30:16 -0400 Subject: [PATCH] begin haproxy implementation --- haproxy.basic | 45 +++++++++++++++++++++++++++++++++++++++++++++ octoprint_deploy.sh | 12 ++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 haproxy.basic diff --git a/haproxy.basic b/haproxy.basic new file mode 100644 index 0000000..db1f35b --- /dev/null +++ b/haproxy.basic @@ -0,0 +1,45 @@ +#Basic setup from: +#https://community.octoprint.org/t/setting-up-octoprint-on-a-computer-running-fedora-centos-almalinux-or-rockylinux/37137/2 +[/etc/haproxy/haproxy.cfg] +global + chroot /var/lib/haproxy + pidfile /var/lib/haproxy.pid + maxconn 4000 + user haproxy + group haproxy + daemon + log 127.0.0.1 local2 + # turn on stats unix socket + stats socket /var/lib/haproxy/stats + + # utilize system-wide crypto-policies + ssl-default-bind-ciphers PROFILE=SYSTEM + ssl-default-server-ciphers PROFILE=SYSTEM + +defaults + log global + mode http + option httplog + option dontlognull + retries 3 + option redispatch + option http-server-close + option forwardfor except 127.0.0.0/8 + timeout http-request 10s + timeout queue 1m + timeout connect 10s + timeout client 1m + timeout server 1m + timeout http-keep-alive 10s + timeout check 10s + +frontend public + bind :::80 v4v6 + option forwardfor except 127.0.0.1 + #use_backend INSTANCE if { path_beg /INSTANCE/ } + default_backend octoprint + +backend octoprint + reqrep ^([^\ :]*)\ /(.*) \1\ /\2 + option forwardfor + server octoprint1 127.0.0.1:5000 diff --git a/octoprint_deploy.sh b/octoprint_deploy.sh index 4dc797b..a660884 100755 --- a/octoprint_deploy.sh +++ b/octoprint_deploy.sh @@ -268,7 +268,7 @@ new_instance () { fi #if we are on octopi, add in haproxy entry - if [ $INSTALL -eq 1 ]; then + if [ $INSTALL -gt 1 ]; then #find frontend line, do insert sed -i "/option forwardfor except 127.0.0.1/a\ use_backend $INSTANCE if { path_beg /$INSTANCE/ }" /etc/haproxy/haproxy.cfg #add backend info, bracket with comments so we can remove later if needed. This all needs work, just slapping stuff in for now @@ -515,6 +515,7 @@ deb_packages() { -e libbsd-dev \ -e ffmpeg \ -e uuid-runtime\ + -e haproxy\ | xargs apt-get install -y | log #pacakges to REMOVE go here @@ -625,7 +626,7 @@ prepare () { fi #Fedora35 if [ $INSTALL -eq 3 ]; then - dnf -y install python3-devel cmake libjpeg-turbo-devel libbsd-devel libevent-devel + dnf -y install python3-devel cmake libjpeg-turbo-devel libbsd-devel libevent-devel haproxy fi echo "Installing OctoPrint in /home/$user/OctoPrint" @@ -646,6 +647,13 @@ prepare () { echo 'Updating config.yaml' sudo -u $user mkdir /home/$user/.octoprint sudo -u $user cp -p $SCRIPTDIR/config.basic /home/$user/.octoprint/config.yaml + echo 'Updating haproxy' + systemctl stop haproxy + mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.orig + cp $SCRIPTDIR/haproxy.basic /etc/haproxy/haproxy.cfg + systemctl start haproxy + systemctl enable haproxy + echo echo echo