fork stop container
This commit is contained in:
42
update-lxc-container.sh
Executable file
42
update-lxc-container.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
declare -A pids
|
||||
|
||||
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 LXC container..."
|
||||
for i in $(lxc list type=container -c ns --format csv); do
|
||||
cont_name=${i%,*}
|
||||
echo $(date) "- Updating ${cont_name} container..."
|
||||
if [ "${i#*,}" == "STOPPED" ]; then
|
||||
echo -e $(date) "- ${BGreen}Start container ${cont_name}${Color_Off}"
|
||||
lxc start ${cont_name}
|
||||
sleep 5
|
||||
else
|
||||
echo -e $(date) "- ${BGreen}Container ${cont_name} is already started${Color_Off}"
|
||||
fi
|
||||
lxc exec ${cont_name} -- sh -c "apt update"
|
||||
sleep 2
|
||||
lxc exec ${cont_name} -- sh -c "apt upgrade -y"
|
||||
sleep 2
|
||||
lxc exec ${cont_name} -- sh -c "apt autoremove"
|
||||
sleep 2
|
||||
if [ "${i#*,}" == "STOPPED" ]; then
|
||||
echo $(date) "- Stop container ${cont_name}"
|
||||
stop_container ${cont_name} &
|
||||
pids[${cont_name}]=$!
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
for pid in ${pids[@]}; do
|
||||
wait $pid
|
||||
done
|
||||
echo $(date) "- Updating LXC container ended"
|
||||
Reference in New Issue
Block a user