Haproxy fix (#63)
* finally fixing haproxy * restart haproxy * fix stop * put extra cams in first cam blocks for removal * need to handle first camera instance * missed a backslash? * missed the start
This commit is contained in:
@@ -36,6 +36,10 @@ get_settings() {
|
||||
#echo $STREAMER
|
||||
HAPROXY=$(cat /etc/octoprint_deploy | sed -n -e 's/^haproxy: \(\.*\)/\1/p')
|
||||
#echo $HAPROXY
|
||||
HAPROXYNEW=$(cat /etc/octoprint_deploy | sed -n -e 's/^haproxynew: \(\.*\)/\1/p')
|
||||
if [ -z "$HAPROXYNEW" ]; then
|
||||
HAPROXYNEW="false"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -272,7 +276,14 @@ new_instance () {
|
||||
if [ "$HAPROXY" == true ]; then
|
||||
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p')
|
||||
#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
|
||||
#Don't know how to do the formatting correctly here. This works, however.
|
||||
SEDREPLACE="#$INSTANCE start\n\
|
||||
acl is_$INSTANCE url_beg /$INSTANCE\n\
|
||||
http-request redirect scheme http drop-query append-slash if is_$INSTANCE ! { path_beg /$INSTANCE/ }\n\
|
||||
use_backend $INSTANCE if { path_beg /$INSTANCE/ }\n\
|
||||
#$INSTANCE stop"
|
||||
|
||||
sed -i "/option forwardfor except 127.0.0.1/a $SEDREPLACE" /etc/haproxy/haproxy.cfg
|
||||
echo "#$INSTANCE start" >> /etc/haproxy/haproxy.cfg
|
||||
echo "backend $INSTANCE" >> /etc/haproxy/haproxy.cfg
|
||||
if [ $HAversion -gt 1 ]; then
|
||||
@@ -378,17 +389,25 @@ write_camera() {
|
||||
if [ -n "$CAMHAPROXY" ]; then
|
||||
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p')
|
||||
#find frontend line, do insert
|
||||
sed -i "/option forwardfor except 127.0.0.1/a\ use_backend cam${INUM}_$INSTANCE if { path_beg /cam${INUM}_$INSTANCE/ }" /etc/haproxy/haproxy.cfg
|
||||
echo "#cam${INUM}_$INSTANCE start" >> /etc/haproxy/haproxy.cfg
|
||||
echo "backend cam${INUM}_$INSTANCE" >> /etc/haproxy/haproxy.cfg
|
||||
sed -i "/use_backend $INSTANCE if/a\ use_backend cam${INUM}_$INSTANCE if { path_beg /cam${INUM}_$INSTANCE/ }" /etc/haproxy/haproxy.cfg
|
||||
if [ $HAversion -gt 1 ]; then
|
||||
echo " http-request replace-path /cam${INUM}_$INSTANCE/(.*) /\1" >> /etc/haproxy/haproxy.cfg
|
||||
echo " server webcam1 127.0.0.1:$CAMPORT" >> /etc/haproxy/haproxy.cfg
|
||||
EXTRACAM="backend cam${INUM}_$INSTANCE\n\
|
||||
http-request replace-path /cam${INUM}_$INSTANCE/(.*) /\1 \n\
|
||||
server webcam1 127.0.0.1:$CAMPORT"
|
||||
else
|
||||
echo " reqrep ^([^\ :]*)\ /cam${INUM}_$INSTANCE/(.*) \1\ /\2" >> /etc/haproxy/haproxy.cfg
|
||||
echo " server webcam1 127.0.0.1:$CAMPORT" >> /etc/haproxy/haproxy.cfg
|
||||
EXTRACAM="backend cam${INUM}_$INSTANCE\n\
|
||||
reqrep ^([^\ :]*)\ /cam${INUM}_$INSTANCE/(.*) \1\ /\2 \n\
|
||||
server webcam1 127.0.0.1:$CAMPORT"
|
||||
fi
|
||||
|
||||
#Need to set this up for first camera
|
||||
if [ -z "$INUM" ]; then
|
||||
echo "#cam_$INSTANCE start" >> /etc/haproxy/haproxy.cfg
|
||||
fi
|
||||
sed -i "/#cam_$INSTANCE start/a $EXTRACAM" /etc/haproxy/haproxy.cfg
|
||||
if [ -z "$INUM" ]; then
|
||||
echo "#cam_$INSTANCE stop" >> /etc/haproxy/haproxy.cfg
|
||||
fi
|
||||
echo "#cam${INUM}_$INSTANCE stop" >> /etc/haproxy/haproxy.cfg
|
||||
systemctl restart haproxy
|
||||
fi
|
||||
}
|
||||
@@ -841,6 +860,8 @@ prepare () {
|
||||
echo
|
||||
if prompt_confirm "Use haproxy?"; then
|
||||
echo 'haproxy: true' >> /etc/octoprint_deploy
|
||||
#Check if using improved haproxy rules
|
||||
echo 'haproxynew: true' >> /etc/octoprint_deploy
|
||||
systemctl stop haproxy
|
||||
#get haproxy version
|
||||
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p')
|
||||
@@ -874,7 +895,6 @@ prepare () {
|
||||
break
|
||||
;;
|
||||
"None")
|
||||
VID=3
|
||||
break
|
||||
;;
|
||||
*) echo "invalid option $REPLY";;
|
||||
@@ -1363,7 +1383,7 @@ instance_status() {
|
||||
}
|
||||
|
||||
main_menu() {
|
||||
VERSION=0.2.0
|
||||
VERSION=0.2.2
|
||||
#reset
|
||||
UDEV=''
|
||||
TEMPUSB=''
|
||||
@@ -1452,6 +1472,28 @@ if [ ! -f /etc/octoprint_deploy ] && [ -f /etc/octoprint_instances ]; then
|
||||
|
||||
fi
|
||||
|
||||
get_settings
|
||||
|
||||
#02/17/23 - This will upgrade haproxy so it will no longer require the trailling slash
|
||||
if [ "$HAPROXYNEW" == false ] && [ "$HAPROXY" == true ]; then
|
||||
#Update haproxy entries
|
||||
echo "Detected older version of haproxy entries. Updating those now."
|
||||
readarray -t instances < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:graph:]]*\) .*/\1/p')
|
||||
unset 'instances[0]'
|
||||
for instance in "${instances[@]}"; do
|
||||
sed -i "/use_backend $instance/d" /etc/haproxy/haproxy.cfg
|
||||
SEDREPLACE="#$instance start\n\
|
||||
acl is_$instance url_beg /$instance\n\
|
||||
http-request redirect scheme http drop-query append-slash if is_$instance ! { path_beg /$instance/ }\n\
|
||||
use_backend $instance if { path_beg /$instance/ }\n\
|
||||
#$instance stop"
|
||||
sed -i "/option forwardfor except 127.0.0.1/a $SEDREPLACE" /etc/haproxy/haproxy.cfg
|
||||
done
|
||||
echo 'haproxynew: true' >> /etc/octoprint_deploy
|
||||
systemctl restart haproxy
|
||||
fi
|
||||
|
||||
|
||||
#command line arguments
|
||||
if [ "$1" == remove ]; then
|
||||
remove_everything
|
||||
|
||||
Reference in New Issue
Block a user