Add status/run/rotate options & improve updater

tools/pve/cron-update-lxcs.sh: add show_status, run_now and rotate_log functions; expose new menu options (Status, Run, Rotate) and enlarge menu. Consolidate license line formatting.

tools/pve/update-lxcs-cron.sh: tighten variable scoping, improve ostype detection and logging, add fallback for hostname, handle unknown OS types, harden apt workflow (retry with By-Hash workaround and refresh lists), skip template containers correctly, add error reporting on container updates, and use a timed shutdown. Update author/license header.

Overall: adds manual control and status/log rotation to the cron manager and makes the container updater more robust and safer for Debian/Ubuntu-based containers.
This commit is contained in:
CanbiZ (MickLesk)
2026-03-26 13:45:02 +01:00
parent 66cd1fb05a
commit d836402348
2 changed files with 95 additions and 15 deletions

View File

@@ -1,9 +1,8 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2026 community-scripts ORG
# Author: tteck (tteckster) | Rewritten by community-scripts
# License: MIT
# https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
# Author: MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
#
# This script is installed locally by cron-update-lxcs.sh and executed
# by cron. It updates all LXC containers using their native package manager.
@@ -26,16 +25,26 @@ if [[ -f "$CONF_FILE" ]]; then
fi
function update_container() {
container=$1
name=$(pct exec "$container" hostname)
echo -e "\n [Info] Updating $container : $name \n"
local container=$1
local name
name=$(pct exec "$container" hostname 2>/dev/null || echo "unknown")
local os
os=$(pct config "$container" | awk '/^ostype/ {print $2}')
echo -e "\n [Info] Updating $container : $name (os: $os)"
case "$os" in
alpine) pct exec "$container" -- ash -c "apk -U upgrade" ;;
archlinux) pct exec "$container" -- bash -c "pacman -Syyu --noconfirm" ;;
fedora | rocky | centos | alma) pct exec "$container" -- bash -c "dnf -y update && dnf -y upgrade" ;;
ubuntu | debian | devuan) pct exec "$container" -- bash -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" dist-upgrade -y; rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED" ;;
ubuntu | debian | devuan) pct exec "$container" -- bash -c '
apt-get update || {
echo "Acquire::By-Hash \"no\";" >/etc/apt/apt.conf.d/99no-by-hash
rm -rf /var/lib/apt/lists/*
apt-get update
}
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" dist-upgrade -y
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED' ;;
opensuse) pct exec "$container" -- bash -c "zypper ref && zypper --non-interactive dup" ;;
*) echo " [Warn] Unknown OS type '$os' for container $container, skipping" ;;
esac
}
@@ -52,16 +61,19 @@ for container in $(pct list | awk '{if(NR>1) print $1}'); do
sleep 1
else
status=$(pct status "$container")
template=$(pct config "$container" | grep -q "template:" && echo "true" || echo "false")
if [ "$template" == "false" ] && [ "$status" == "status: stopped" ]; then
if pct config "$container" 2>/dev/null | grep -q "^template:"; then
echo -e "[Info] Skipping template $container"
continue
fi
if [ "$status" == "status: stopped" ]; then
echo -e "[Info] Starting $container"
pct start "$container"
sleep 5
update_container "$container"
update_container "$container" || echo " [Error] Update failed for $container"
echo -e "[Info] Shutting down $container"
pct shutdown "$container" &
pct shutdown "$container" --timeout 60 &
elif [ "$status" == "status: running" ]; then
update_container "$container"
update_container "$container" || echo " [Error] Update failed for $container"
fi
fi
done