Files
ProxmoxVE/ct/zabbix.sh
T
FlorianandCanbiZ 2dcdbb4b08 Zabbix: keep unattended updates on the installed series (#18051)
* fix(zabbix): keep unattended updates on the installed series

update_script() asked for a Zabbix version unconditionally. update-apps.sh
exports PHS_SILENT=1 for unattended runs, so that read either blocks the
whole batch or, with stdin closed, fails the container with exit 1 after
its services were already stopped.

Resolve the installed series from the zabbix-release package before
touching systemd, and ask only when the run is interactive. Unattended
runs stay on the installed series and still get minor and patch updates;
changing series remains an attended decision. When the series cannot be
read, exit 75 so the batch logs the container as skipped instead of
failing it.

Fixes #18046

* Clean up comments in zabbix.sh

Removed comments regarding unattended runs and series changes.

---------

Co-authored-by: CanbiZ (MickLesk) <47820557+MickLesk@users.noreply.github.com>
2026-10-22 10:49:14 +02:00

140 lines
5.0 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
_cs_boot="${COMMUNITY_SCRIPTS_CORE_DIR:-$(dirname "${BASH_SOURCE[0]}")/../../core}/core/build.func"
source "$_cs_boot" 2>/dev/null || source <(curl -fsSL "${COMMUNITY_SCRIPTS_CORE_URL:-https://raw.githubusercontent.com/community-scripts/core/main}/core/build.func")
# Copyright (c) 2021-2026 community-scripts ORG
# Author: MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://www.zabbix.com/
APP="Zabbix"
var_tags="${var_tags:-monitoring}"
var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-4096}"
var_disk="${var_disk:-6}"
var_os="${var_os:-debian}"
var_version="${var_version:-13}"
var_arm64="${var_arm64:-yes}"
var_unprivileged="${var_unprivileged:-1}"
header_info "$APP"
variables
color
catch_errors
function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -f /etc/zabbix/zabbix_server.conf ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
. /etc/os-release
if [ "$VERSION_CODENAME" != "trixie" ]; then
msg_error "Unsupported Debian version: $VERSION_CODENAME – please upgrade to Debian 13 (Trixie) before updating Zabbix."
exit
fi
if systemctl cat zabbix-agent2.service &>/dev/null; then
AGENT_SERVICE="zabbix-agent2"
elif systemctl cat zabbix-agent.service &>/dev/null; then
AGENT_SERVICE="zabbix-agent"
else
AGENT_SERVICE=""
msg_warn "No Zabbix Agent service found, skipping agent actions"
fi
ZABBIX_SERIES="$(dpkg-query -W -f='${Version}' zabbix-release 2>/dev/null || true)"
ZABBIX_SERIES="${ZABBIX_SERIES#*:}"
ZABBIX_SERIES="${ZABBIX_SERIES%%[!0-9.]*}"
if [[ "${PHS_SILENT:-0}" == "1" ]]; then
if [[ ! "$ZABBIX_SERIES" =~ ^[0-9]+\.[0-9]+$ ]]; then
msg_warn "Could not detect the installed Zabbix series - skipping update, requires an interactive run"
exit 75
fi
ZABBIX_VERSION="$ZABBIX_SERIES"
msg_warn "Unattended update: staying on Zabbix ${ZABBIX_VERSION}"
else
read -rp "Choose Zabbix version [1] 7.0 LTS [2] 7.4 (Latest Stable) [3] Latest available (default: 2): " ZABBIX_CHOICE
ZABBIX_CHOICE=${ZABBIX_CHOICE:-2}
case "$ZABBIX_CHOICE" in
1) ZABBIX_VERSION="7.0" ;;
2) ZABBIX_VERSION="7.4" ;;
3) ZABBIX_VERSION=$(curl -fsSL https://repo.zabbix.com/zabbix/ |
grep -oP '(?<=href=")[0-9]+\.[0-9]+(?=/")' | sort -V | tail -n1) ;;
*)
ZABBIX_VERSION="7.4"
echo "Invalid choice. Defaulting to 7.4."
;;
esac
fi
msg_info "Stopping Services"
systemctl stop zabbix-server
[[ -n "$AGENT_SERVICE" ]] && systemctl stop "$AGENT_SERVICE"
msg_ok "Stopped Services"
msg_info "Updating Zabbix to $ZABBIX_VERSION"
mkdir -p /opt/zabbix-backup/
cp /etc/zabbix/zabbix_server.conf /opt/zabbix-backup/
cp /etc/apache2/conf-enabled/zabbix.conf /opt/zabbix-backup/
cp -R /usr/share/zabbix/ /opt/zabbix-backup/
rm -Rf /etc/apt/sources.list.d/zabbix.list
cd /tmp
if [[ "$ZABBIX_VERSION" == "7.0" ]]; then
ZABBIX_DEB_URL="https://repo.zabbix.com/zabbix/${ZABBIX_VERSION}/debian/pool/main/z/zabbix-release/zabbix-release_latest_${ZABBIX_VERSION}+debian13_all.deb"
ZABBIX_DEB_FILE="zabbix-release_latest_${ZABBIX_VERSION}+debian13_all.deb"
else
ZABBIX_DEB_URL="https://repo.zabbix.com/zabbix/${ZABBIX_VERSION}/release/debian/pool/main/z/zabbix-release/zabbix-release_latest+debian13_all.deb"
ZABBIX_DEB_FILE="zabbix-release_latest+debian13_all.deb"
fi
curl -fsSL "$ZABBIX_DEB_URL" -o /tmp/"$ZABBIX_DEB_FILE"
$STD dpkg -i /tmp/"$ZABBIX_DEB_FILE"
rm -rf /tmp/zabbix-release_*.deb
apt_update_safe
$STD apt install --only-upgrade -y zabbix-server-pgsql zabbix-frontend-php php8.4-pgsql
if [[ "$AGENT_SERVICE" == "zabbix-agent2" ]]; then
$STD apt install --only-upgrade -y zabbix-agent2 zabbix-agent2-plugin-postgresql
if [ -f /etc/zabbix/zabbix_agent2.d/plugins.d/nvidia.conf ]; then
sed -i 's|^Plugins.NVIDIA.System.Path=.*|# Plugins.NVIDIA.System.Path=/usr/libexec/zabbix/zabbix-agent2-plugin-nvidia-gpu|' \
/etc/zabbix/zabbix_agent2.d/plugins.d/nvidia.conf
fi
elif [[ "$AGENT_SERVICE" == "zabbix-agent" ]]; then
$STD apt install --only-upgrade -y zabbix-agent
fi
if command -v fping >/dev/null 2>&1; then
FPING_PATH=$(command -v fping)
sed -i "s|^#\?FpingLocation=.*|FpingLocation=$FPING_PATH|" /etc/zabbix/zabbix_server.conf
fi
if command -v fping6 >/dev/null 2>&1; then
FPING6_PATH=$(command -v fping6)
sed -i "s|^#\?Fping6Location=.*|Fping6Location=$FPING6_PATH|" /etc/zabbix/zabbix_server.conf
fi
msg_ok "Updated Zabbix"
msg_info "Starting Services"
systemctl start zabbix-server
[[ -n "$AGENT_SERVICE" ]] && systemctl start "$AGENT_SERVICE"
systemctl restart apache2
msg_ok "Started Services"
msg_ok "Updated successfully!"
exit
}
start
build_container
description
msg_ok "Completed successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW}Access it using the following URL:${CL}"
echo -e "${GATEWAY}${BGN}http://${IP}/zabbix${CL}"