lxc -> incus

This commit is contained in:
2025-03-23 11:26:28 +01:00
parent b0067645ba
commit 1b0b27d94a
12 changed files with 155 additions and 113 deletions

50
update-incus-virtualMachine.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/bash
declare -A pids
BRed='\033[1;31m' # Red
BGreen='\033[1;32m' # Green
Color_Off='\033[0m' # Text Reset
TMSTMP=$(date +'%Y%m%d%H%M%S')
function stop_virtualMachine() {
sleep 120
incus stop ${1}
echo -e $(date) "- ${BGreen}Virtual Machine ${1} stopped${Color_Off}"
}
echo $(date) "- Start updating incus Virtual Machine..."
for vm_name in $(incus list type=virtual-machine -c n --format csv); do
echo $(date) "- Make ${vm_name} Virtual Machine snapshot..."
incus snapshot create ${vm_name}
echo $(date) "- Updating ${vm_name} Virtual Machine..."
Status=$(incus list type=virtual-machine -c ns --format csv | grep ${vm_name} | cut -d',' -f 2)
if [ "${Status}" == "STOPPED" ]; then
echo -e $(date) "- ${BGreen}Start Virtual Machine ${vm_name}${Color_Off}"
incus start ${vm_name}
sleep 5
else
echo -e $(date) "- ${BGreen}Virtual Machine ${vm_name} is already started${Color_Off}"
fi
incus exec ${vm_name} -- sh -c "apt update"
sleep 2
incus exec ${vm_name} -- sh -c "apt upgrade -y"
sleep 2
incus exec ${vm_name} -- sh -c "apt autoremove"
sleep 2
echo -e $(date) "- Refresh snap packages"
incus exec ${vm_name} -- bash -c "if [[ \$(which snap > /dev/null; echo \$?) == 0 ]]; then snap refresh ; fi"
if [ "${Status}" = "STOPPED" ]; then
echo $(date) "- Stop Virtual Machine ${vm_name}"
stop_virtualMachine ${vm_name} &
pids[${vm_name}]=$!
fi
sleep 2
done
for pid in ${pids[@]}; do
wait $pid
done
echo $(date) "- Updating incus Virtual Machine ended"