fix: introduce new/better folder structure for multi instance setups

This commit is contained in:
th33xitus
2021-01-09 23:17:45 +01:00
parent d066999d0b
commit 9ea29bf995
2 changed files with 65 additions and 35 deletions

View File

@@ -76,7 +76,7 @@ create_klipper_virtualenv(){
create_single_klipper_startscript(){
### create systemd service file
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper.service" << EOF
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper.service" << SINGLE_STARTSCRIPT
#Systemd service file for klipper
[Unit]
Description=Starts klipper on startup
@@ -90,12 +90,12 @@ RemainAfterExit=yes
ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
Restart=always
RestartSec=10
EOF
SINGLE_STARTSCRIPT
}
create_multi_klipper_startscript(){
### create multi instance systemd service file
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper-$INSTANCE.service" << EOF
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper-$INSTANCE.service" << MULTI_STARTSCRIPT
#Systemd service file for klipper
[Unit]
Description=Starts klipper instance $INSTANCE on startup
@@ -109,7 +109,26 @@ RemainAfterExit=yes
ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -I ${TMP_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
Restart=always
RestartSec=10
EOF
MULTI_STARTSCRIPT
}
create_minimal_printer_cfg(){
/bin/sh -c "cat > $1" << MINIMAL_CFG
[mcu]
serial: /dev/serial/by-id/
pin_map: arduino
[pause_resume]
[display_status]
[virtual_sdcard]
path: ~/gcode_files
[printer]
kinematics: none
max_velocity: 1
max_accel: 1
MINIMAL_CFG
}
klipper_setup(){
@@ -129,9 +148,9 @@ klipper_setup(){
install_klipper_packages
create_klipper_virtualenv
### create sdcard folder
[ ! -d ${HOME}/sdcard ] && mkdir -p ${HOME}/sdcard
### create config folder
### create shared gcode_files folder
[ ! -d ${HOME}/gcode_files ] && mkdir -p ${HOME}/gcode_files
### create shared config folder
[ ! -d $PRINTER_CFG_LOC ] && mkdir -p $PRINTER_CFG_LOC
### create klipper instances
@@ -155,6 +174,7 @@ create_single_klipper_instance(){
status_msg "Creating single Klipper instance ..."
status_msg "Installing system start script ..."
create_single_klipper_startscript
[ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG"
### enable instance
sudo systemctl enable klipper.service
@@ -165,7 +185,8 @@ create_single_klipper_instance(){
sudo systemctl start klipper
### confirm message
ok_msg "Single Klipper instance has been set up!\n"
CONFIRM_MSG="Single Klipper instance has been set up!"
print_msg && clear_msg
}
create_multi_klipper_instance(){
@@ -175,7 +196,11 @@ create_multi_klipper_instance(){
KLIPPER_LOG=/tmp/klippy-$INSTANCE.log
KLIPPY_UDS=/tmp/klippy_uds-$INSTANCE
TMP_PRINTER=/tmp/printer-$INSTANCE
PRINTER_CFG="$PRINTER_CFG_LOC/printer-$INSTANCE.cfg"
PRINTER_CFG="$PRINTER_CFG_LOC/printer_$INSTANCE/printer.cfg"
### create printer config folder and write a minimal printer.cfg to it
[ ! -d $PRINTER_CFG_LOC/printer_$INSTANCE ] && mkdir -p $PRINTER_CFG_LOC/printer_$INSTANCE
[ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG"
### create instance
status_msg "Creating instance #$INSTANCE ..."
@@ -192,10 +217,18 @@ create_multi_klipper_instance(){
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
### confirm message
ok_msg "$INSTANCE_COUNT Klipper instances have been set up!\n"
CONFIRM_MSG="$INSTANCE_COUNT Klipper instances have been set up!"
print_msg && clear_msg
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
flash_routine(){
echo
top_border

View File

@@ -20,7 +20,8 @@ moonraker_setup_dialog(){
### check system for python3 before initializing the moonraker installation
python3_check
if [ $py_chk_ok = "false" ]; then
return 0
ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first."
print_msg && clear_msg && return 0
fi
status_msg "Initializing Moonraker installation ..."
@@ -157,6 +158,7 @@ moonraker_setup(){
create_moonraker_virtualenv
### create moonraker.conf folder
### athough it should already exist because its the same as the klipper config folder
[ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC
### create moonraker.confs
@@ -200,7 +202,8 @@ create_single_moonraker_instance(){
sudo systemctl start moonraker
### confirm message
ok_msg "Single Moonraker instance has been set up!"
CONFIRM_MSG="Single Moonraker instance has been set up!"
print_msg && clear_msg
### display moonraker ip to the user
print_ip_list; echo
@@ -211,7 +214,7 @@ create_multi_moonraker_instance(){
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
### multi instance variables
MOONRAKER_LOG=/tmp/moonraker-$INSTANCE.log
MOONRAKER_CONF="$MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf"
MOONRAKER_CONF="$MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf"
### create instance
status_msg "Creating instance #$INSTANCE ..."
@@ -228,9 +231,10 @@ create_multi_moonraker_instance(){
### instance counter +1
INSTANCE=$(expr $INSTANCE + 1)
done
### confirm message
echo; echo;
ok_msg "$INSTANCE_COUNT Moonraker instances have been set up!"
CONFIRM_MSG="$INSTANCE_COUNT Moonraker instances have been set up!"
print_msg && clear_msg
### display all moonraker ips to the user
print_ip_list; echo
@@ -278,9 +282,9 @@ moonraker_conf_creation(){
ip_list+=("$HOSTNAME:$PORT")
### start the creation of each instance
status_msg "Creating moonraker-$INSTANCE.conf in $MOONRAKER_CONF_LOC"
if [ ! -f $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf ]; then
create_multi_moonraker_conf && ok_msg "moonraker-$INSTANCE.conf created!"
status_msg "Creating moonraker.conf for instance #$INSTANCE"
if [ ! -f $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf ]; then
create_multi_moonraker_conf && ok_msg "moonraker.conf created!"
else
warn_msg "There is already a file called 'moonraker-$INSTANCE.conf'!"
warn_msg "Skipping..."
@@ -312,6 +316,8 @@ trusted_clients:
$LOCAL_NETWORK
cors_domains:
http://*.local
http://my.mainsail.app
https://my.mainsail.app
http://app.fluidd.xyz
https://app.fluidd.xyz
http://$HOSTNAME
@@ -324,15 +330,15 @@ MOONRAKERCONF
create_multi_moonraker_conf(){
HOSTNAME=$(hostname -I | cut -d" " -f1)
NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24"
LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24"
/bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf" << MOONRAKERCONF
/bin/sh -c "cat > $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf" << MOONRAKERCONF
[server]
host: 0.0.0.0
port: $PORT
klippy_uds_address: /tmp/klippy_uds-$INSTANCE
enable_debug_logging: True
config_path: $PRINTER_CFG_LOC
config_path: $PRINTER_CFG_LOC/printer_$INSTANCE
[authorization]
enabled: True
@@ -342,6 +348,8 @@ trusted_clients:
$LOCAL_NETWORK
cors_domains:
http://*.local
http://my.mainsail.app
https://my.mainsail.app
http://app.fluidd.xyz
https://app.fluidd.xyz
http://$HOSTNAME
@@ -353,20 +361,9 @@ MOONRAKERCONF
}
##############################################################################################
#********************************************************************************************#
##############################################################################################
install_moonraker(){