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:
@@ -1,4 +1,4 @@
|
||||
Updated December 30, 2022.
|
||||
Updated February 17, 2023.
|
||||
Want to support this work? Buy Me a Coffee. https://www.buymeacoffee.com/ppaukstelis.
|
||||
Need help with octoprint_deploy? Ask on Discord: https://discord.gg/6vgSjgvR6u
|
||||
# octoprint_deploy
|
||||
@@ -21,7 +21,7 @@ These files provide a bash script for quickly deploying multiple octoprint insta
|
||||
* Do not plug your printer in by USB until you are asked to do so.
|
||||
* If your printer does not have a serial number (all Creality printers), it will detect and use the physical USB address for udev entries.
|
||||
* Continue until you have added all the printers you want to use.
|
||||
* haproxy entries are updated so you can connect via http://octopi.local/instancename/ (trailing slash is needed).
|
||||
* haproxy entries are updated so you can connect via http://octopi.local/instancename
|
||||
* Please note, haproxy entries are NOT used for webcams once you use this system. Connect to them via hostname:port.
|
||||
* To add more printers at a later date, just run the script again!
|
||||
* Want to use a Pi camera? After you have made your instance(s), run the script with `sudo octoprint_deploy/octoprint_deploy.sh picam` and follow the instructions (VERY EXPERIMENTAL).
|
||||
@@ -36,7 +36,7 @@ These files provide a bash script for quickly deploying multiple octoprint insta
|
||||
* run the command `git clone https://github.com/paukstelis/octoprint_deploy.git`.
|
||||
* run the command `sudo octoprint_deploy/octoprint_deploy.sh`.
|
||||
* Choose `Prepare System` from the menu. Select your distribution type. All deb-based system use the same selection. This will install necessary packages, install OctoPrint, and start a template instance.
|
||||
* You will be asked if you want to use haproxy. This will make your instances available on port 80 e.g. http://hostname.local/instancename/. PLEASE NOTE that the trailing slash is required!
|
||||
* You will be asked if you want to use haproxy. This will make your instances available on port 80 e.g. http://hostname.local/instancename/
|
||||
* You will be asked which streamer you would like to install (mjpg-streamer or ustreamer).
|
||||
* You will be prompted if you want to setup the admin user and do the first run wizard via the commandline. If you do this now you can start making new instances as soon as the system preparation is complete.
|
||||
* You will be prompted if you want to install recommended plugins and cloud plugins. This can be useful if you want to configure plugins in your template instance, before adding new instances.
|
||||
@@ -60,6 +60,7 @@ These files provide a bash script for quickly deploying multiple octoprint insta
|
||||
* Change udev rules for an instance with `sudo octoprint_deploy/octoprint_deploy.sh replace`
|
||||
* Always a good idea to update octoprint_deploy from time-to-time with `git -C octoprint_deploy pull`
|
||||
# Recent Changes
|
||||
* Haproxy fixed! No more trailing slash required! Running new octoprint_deploy on an older installation automatically update these entries.
|
||||
* Multi-camera support (experimental). Clean-up of haproxy.cfg on instance removal still needs work.
|
||||
* If haproxy is used, cameras stream can be placed behind it. PLEASE NOTE: if cameras are used with haproxy a relative stream path is used. This means that your stream will not show up in the Control tab unless you access with the haproxy path (http://host/instancename/) (remember, trailing slash is required!)
|
||||
* Allow making backups of generic instance.
|
||||
|
||||
@@ -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