improve update, middleware restart and version checking behavior

This commit is contained in:
Kjeld Schouten-Lebbing 2022-12-27 13:04:26 +01:00
parent 2b7e8131be
commit 89fa678cd9
3 changed files with 31 additions and 14 deletions

View File

@ -25,18 +25,21 @@ export -f kubeapiEnable
# Prune unused docker images to prevent dataset/snapshot bloat related slowdowns on SCALE
prune(){
echo -e "${BWhite}Docker Prune${Color_Off}"
echo "Pruning Docker Images..."
docker image prune -af | grep "^Total" && echo -e "${IGreen}Docker Prune Successfull${Color_Off}" || echo "Docker Prune ${IRed}FAILED${Color_Off}"
# TODO Switch to middleware prune on next release
# midclt call container.prune '{"remove_unused_images": true, "remove_stopped_containers": true}' &> /dev/null && echo "Docker Prune completed"|| echo "Docker Prune ${IRed}FAILED${Color_Off}"
echo -e "🄿 🅁 🅄 🄽 🄴"
if (( "$scaleVersion" >= 22120 )); then
cli -c 'app container config prune prune_options={"remove_unused_images": true, "remove_stopped_containers": true}' | head -n -4 || echo "Failed to Prune Docker Images"
else
docker image prune -af | grep "^Total" || echo "Failed to Prune Docker Images"
fi
}
export -f prune
#
sync(){
echo -e "${BWhite}Starting Catalog Sync...${Color_Off}"
cli -c 'app catalog sync_all' &> /dev/null && echo -e "${IGreen}Catalog sync complete${Color_Off}" || echo -e "${IRed}Catalog Sync Failed${Color_Off}"
middlewareRestart() {
echo "We need to restart middlewared."
echo "This will cause a short downtime for the webui approximately 10-30 seconds"
echo "Restarting middlewared"
service middlewared restart &
wait $!
echo "Restarted middlewared"
}
export -f sync
export -f middlewareRestart

View File

@ -2,17 +2,29 @@
patchv22120(){
echo "Applying 22.12 HotPatch 1"
( wget -q -P /tmp https://github.com/truecharts/truetool/raw/main/hotpatch/2212/HP1.patch && echo "download completed" || echo "download failed" ) && ( patch -N -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ < /tmp/HP1.patch && service middlewared restart && echo "waiting 20 seconds for middleware restart..." && sleep 20 && echo "patch completed" || echo "patch failed or skipped, not critical" ) && rm -rf /tmp/HP1.patch
( wget -q -P /tmp https://github.com/truecharts/truetool/raw/main/hotpatch/2212/HP1.patch && echo "download completed" || echo "download failed" ) && ( patch -N -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ &>/dev/null < /tmp/HP1.patch && echo "patch completed" || echo "Patch Already Applied" ) && rm -rf /tmp/HP1.patch
echo "Applying 22.12 HotPatch 2"
( wget -q -P /tmp https://github.com/truecharts/truetool/raw/main/hotpatch/2212/HP2.patch && echo "download completed" || echo "download failed" ) && ( patch -N -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ < /tmp/HP2.patch && service middlewared restart && echo "waiting 20 seconds for middleware restart..." && sleep 20 && echo "patch completed" || echo "patch failed or skipped, not critical" ) && rm -rf /tmp/HP2.patch
( wget -q -P /tmp https://github.com/truecharts/truetool/raw/main/hotpatch/2212/HP2.patch && echo "download completed" || echo "download failed" ) && ( patch -N -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ &>/dev/null < /tmp/HP2.patch && echo "patch completed" || echo "Patch Already Applied" ) && rm -rf /tmp/HP2.patch
}
export -f patchv22120
hotpatch(){
echo "Starting hotpatcher..."
if [ "$(cli -m csv -c 'system version' | awk -F '-' '{print $3}')" == "22.12.0" ]; then
restartmiddleware=no
if (( "$scaleVersion" == 22120 )); then
patchv22120
restartmiddleware=yes
else
echo "No hotpatch available for your version, congratulations!"
fi
if (( "$restartmiddleware" == "yes" )); then
middlewareRestart
fi
}
export -f hotpatch

View File

@ -131,6 +131,8 @@ title
[[ "$enableUpdate" == "true" ]] && updater "$@"
scaleVersion=$(version="$(cli -c 'system version' | awk -F '-' '{print $3}' | awk -F '.' '{print $1 $2 $3}' | tr -d " \t\r\.")")
## Always check if a hotpatch needs to be applied
hotpatch