mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-14 02:54:28 +05:00
fix: rework dwc and octoprint service handling
This commit is contained in:
@@ -171,72 +171,72 @@ moonraker_service(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
start_dwc(){
|
dwc_service(){
|
||||||
status_msg "Starting DWC-for-Klipper-Socket Service ..."
|
### set a variable for the ok and status messages
|
||||||
sudo systemctl start dwc && ok_msg "DWC-for-Klipper-Socket Service started!"
|
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
|
||||||
}
|
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
|
||||||
|
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
|
||||||
|
|
||||||
stop_dwc(){
|
if ls /etc/systemd/system/dwc-*.service 2>/dev/null 1>&2; then
|
||||||
status_msg "Stopping DWC-for-Klipper-Socket Service ..."
|
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc-[[:digit:]].service" | wc -l)
|
||||||
sudo systemctl stop dwc && ok_msg "DWC-for-Klipper-Socket Service stopped!"
|
INSTANCE=1
|
||||||
}
|
status_msg "$ACTION2 $INSTANCE_COUNT DWC-for-Klipper-Socket Services ..."
|
||||||
|
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
||||||
start_octoprint(){
|
sudo systemctl $1 dwc-$INSTANCE && ok_msg "DWC-for-Klipper-Socket Service #$INSTANCE $ACTION1!"
|
||||||
status_msg "Starting OctoPrint Service ..."
|
### instance counter +1
|
||||||
sudo systemctl start octoprint && ok_msg "OctoPrint Service started!"
|
INSTANCE=$(expr $INSTANCE + 1)
|
||||||
}
|
done
|
||||||
|
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc.service")" ]; then
|
||||||
stop_octoprint(){
|
status_msg "$ACTION2 DWC-for-Klipper-Socket Service ..."
|
||||||
status_msg "Stopping OctoPrint Service ..."
|
sudo systemctl $1 dwc && ok_msg "DWC-for-Klipper-Socket Service $ACTION1!"
|
||||||
sudo systemctl stop octoprint && ok_msg "OctoPrint Service stopped!"
|
|
||||||
}
|
|
||||||
|
|
||||||
restart_octoprint(){
|
|
||||||
status_msg "Restarting OctoPrint Service ..."
|
|
||||||
sudo systemctl restart octoprint && ok_msg "OctoPrint Service restarted!"
|
|
||||||
}
|
|
||||||
|
|
||||||
enable_octoprint_service(){
|
|
||||||
if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then
|
|
||||||
status_msg "OctoPrint Service is disabled! Enabling now ..."
|
|
||||||
sudo systemctl enable octoprint -q && sudo systemctl start octoprint
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
disable_octoprint(){
|
octoprint_service(){
|
||||||
if [ "$DISABLE_OPRINT" = "true" ]; then
|
### set a variable for the ok and status messages
|
||||||
disable_octoprint_service
|
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
|
||||||
fi
|
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
|
||||||
}
|
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
|
||||||
|
[ "$1" == "enable" ] && ACTION1="enabled" && ACTION2="Enabling"
|
||||||
|
[ "$1" == "disable" ] && ACTION1="disabled" && ACTION2="Disabling"
|
||||||
|
|
||||||
disable_octoprint_service(){
|
if ls /etc/systemd/system/octoprint-*.service 2>/dev/null 1>&2; then
|
||||||
if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then
|
INSTANCE=1
|
||||||
status_msg "OctoPrint Service is enabled! Disabling now ..."
|
INSTANCE_COUNT=$(systemctl list-unit-files | grep -E "octoprint.*" | wc -l)
|
||||||
sudo systemctl stop octoprint && sudo systemctl disable octoprint -q
|
status_msg "$ACTION2 $INSTANCE_COUNT OctoPrint Services ..."
|
||||||
|
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
||||||
|
sudo systemctl $1 octoprint-$INSTANCE && ok_msg "OctoPrint Service #$INSTANCE $ACTION1!"
|
||||||
|
### instance counter +1
|
||||||
|
INSTANCE=$(expr $INSTANCE + 1)
|
||||||
|
done
|
||||||
|
elif [ "$(systemctl list-unit-files | grep -E "octoprint.*")" ]; then
|
||||||
|
status_msg "$ACTION2 OctoPrint Service ..."
|
||||||
|
sudo systemctl $1 octoprint && ok_msg "OctoPrint Service $ACTION1!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle_octoprint_service(){
|
toggle_octoprint_service(){
|
||||||
if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then
|
if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
|
||||||
if systemctl is-enabled octoprint.service -q; then
|
octoprint_service "stop"
|
||||||
disable_octoprint_service
|
octoprint_service "disable"
|
||||||
sleep 2
|
sleep 2
|
||||||
CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !"
|
CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !"
|
||||||
else
|
elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then
|
||||||
enable_octoprint_service
|
octoprint_service "enable"
|
||||||
sleep 2
|
octoprint_service "start"
|
||||||
CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !"
|
sleep 2
|
||||||
fi
|
CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !"
|
||||||
else
|
else
|
||||||
ERROR_MSG=" You cannot activate a service that does not exist!"
|
ERROR_MSG=" You cannot activate a service that does not exist!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
read_octoprint_service_status(){
|
read_octoprint_service_status(){
|
||||||
if ! systemctl is-enabled octoprint.service -q &>/dev/null; then
|
unset OPRINT_SERVICE_STATUS
|
||||||
OPRINT_SERVICE_STATUS="${green}[Enable]${default} OctoPrint Service "
|
if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then
|
||||||
else
|
|
||||||
OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service "
|
OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service "
|
||||||
|
else
|
||||||
|
OPRINT_SERVICE_STATUS="${green}[Enable]${default} OctoPrint Service "
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,14 +97,14 @@ update_klipper(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_dwc2fk(){
|
update_dwc2fk(){
|
||||||
stop_dwc
|
dwc_service "stop"
|
||||||
bb4u "dwc2"
|
bb4u "dwc2"
|
||||||
if [ ! -d $DWC2FK_DIR ]; then
|
if [ ! -d $DWC2FK_DIR ]; then
|
||||||
cd ${HOME} && git clone $DWC2FK_REPO
|
cd ${HOME} && git clone $DWC2FK_REPO
|
||||||
else
|
else
|
||||||
cd $DWC2FK_DIR && git pull
|
cd $DWC2FK_DIR && git pull
|
||||||
fi
|
fi
|
||||||
start_dwc
|
dwc_service "start"
|
||||||
}
|
}
|
||||||
|
|
||||||
update_dwc2(){
|
update_dwc2(){
|
||||||
@@ -125,9 +125,9 @@ update_fluidd(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_moonraker(){
|
update_moonraker(){
|
||||||
|
moonraker_service "stop"
|
||||||
bb4u "moonraker"
|
bb4u "moonraker"
|
||||||
status_msg "Updating Moonraker ..."
|
status_msg "Updating Moonraker ..."
|
||||||
moonraker_service "stop"; echo
|
|
||||||
cd $MOONRAKER_DIR
|
cd $MOONRAKER_DIR
|
||||||
MOONRAKER_OLDREQ_MD5SUM=$(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1)
|
MOONRAKER_OLDREQ_MD5SUM=$(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user