add snap app refresh
This commit is contained in:
42
update-lxc-single-container.sh
Executable file
42
update-lxc-single-container.sh
Executable 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"
|
||||
Reference in New Issue
Block a user