add snap app refresh

This commit is contained in:
2024-02-05 20:50:25 +01:00
parent 594e05bf5c
commit d3bbc8380d
3 changed files with 46 additions and 1 deletions

2
.gitignore vendored
View File

@@ -1 +1 @@
logs/rsync-backup.log logs/

View File

@@ -28,6 +28,9 @@ for i in $(lxc list type=container -c ns --format csv); do
sleep 2 sleep 2
lxc exec ${cont_name} -- sh -c "apt autoremove" lxc exec ${cont_name} -- sh -c "apt autoremove"
sleep 2 sleep 2
echo -e $(date) "- Refresh snap packages"
lxc exec ${cont_name} -- bash -c "if [[ \$(which snap > /dev/null; echo \$?) == 0 ]]; then snap refresh ; fi"
if [ "${i#*,}" == "STOPPED" ]; then if [ "${i#*,}" == "STOPPED" ]; then
echo $(date) "- Stop container ${cont_name}" echo $(date) "- Stop container ${cont_name}"
stop_container ${cont_name} & stop_container ${cont_name} &

42
update-lxc-single-container.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/bash
BRed='\033[1;31m' # Red
BGreen='\033[1;32m' # Green
Color_Off='\033[0m' # Text Reset
function stop_container() {
lxc stop ${1}
echo -e $(date) "- ${BGreen}Container ${1} stopped${Color_Off}"
}
echo $(date) "- Start updating $1 LXC container..."
status=$(lxc info microk8s | grep Status | cut -d' ' -f 2)
echo $(date) "- Updating $1 container..."
if [ $status == "STOPPED" ]; then
echo -e $(date) "- ${BGreen}Start container $1${Color_Off}"
lxc start $1
sleep 5
else
echo -e $(date) "- ${BGreen}Container $1 is already started${Color_Off}"
fi
lxc exec $1 -- sh -c "apt update"
sleep 2
lxc exec $1 -- sh -c "apt upgrade -y"
sleep 2
lxc exec $1 -- sh -c "apt autoremove"
sleep 2
echo -e $(date) "- Refresh snap packages"
lxc exec $1 -- bash -c "if [[ \$(which snap > /dev/null; echo \$?) == 0 ]]; then snap refresh ; fi"
if [ $status == "STOPPED" ]; then
echo $(date) "- Stop container $1"
stop_container $1 &
pids[$1]=$!
fi
sleep 2
for pid in ${pids[@]}; do
wait $pid
done
echo $(date) "- Updating LXC container ended"