From 85b38134d0d26455c89f32b738f075ee29566eba Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Tue, 10 Dec 2024 14:42:04 +0900 Subject: [PATCH] WIP --- .github/workflows/apt.yml | 2 + .github/workflows/yum.yml | 4 + fluent-package/apt/commonvar.sh | 2 + .../apt/systemd-test/downgrade-to-v5.sh | 28 +++++++ .../apt/systemd-test/update-from-v5.sh | 69 ++++++++++++++++ fluent-package/yum/systemd-test/commonvar.sh | 1 + .../yum/systemd-test/downgrade-to-v5.sh | 46 +++++++++++ .../yum/systemd-test/update-from-v5.sh | 79 +++++++++++++++++++ 8 files changed, 231 insertions(+) create mode 100755 fluent-package/apt/systemd-test/downgrade-to-v5.sh create mode 100755 fluent-package/apt/systemd-test/update-from-v5.sh create mode 100755 fluent-package/yum/systemd-test/downgrade-to-v5.sh create mode 100755 fluent-package/yum/systemd-test/update-from-v5.sh diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index 3c3e7c848..5d98f4d7f 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -165,7 +165,9 @@ jobs: - "update-from-v4.sh local" - "update-from-v4.sh v5" - "update-from-v4.sh lts" + - "update-from-v5.sh" - "downgrade-to-v4.sh" + - "downgrade-to-v5.sh" - "install-newly.sh local" - "install-newly.sh v5" - "install-newly.sh lts" diff --git a/.github/workflows/yum.yml b/.github/workflows/yum.yml index b46cdc618..613a84344 100644 --- a/.github/workflows/yum.yml +++ b/.github/workflows/yum.yml @@ -140,7 +140,9 @@ jobs: - AmazonLinux 2023 x86_64 test: - "update-from-v4.sh" + - "update-from-v5.sh" - "downgrade-to-v4.sh" + - "downgrade-to-v5.sh" - "install-newly.sh local" - "install-newly.sh v5" - "install-newly.sh lts" @@ -214,7 +216,9 @@ jobs: - AlmaLinux 9 x86_64 test: - "update-from-v4.sh" + - "update-from-v5.sh" - "downgrade-to-v4.sh" + - "downgrade-to-v5.sh" - "install-newly.sh local" - "install-newly.sh v5" - "install-newly.sh lts" diff --git a/fluent-package/apt/commonvar.sh b/fluent-package/apt/commonvar.sh index 11147319b..597bb131f 100644 --- a/fluent-package/apt/commonvar.sh +++ b/fluent-package/apt/commonvar.sh @@ -3,6 +3,8 @@ architecture=$(dpkg --print-architecture) repositories_dir=/fluentd/fluent-package/apt/repositories java_jdk=openjdk-11-jre td_agent_version=4.5.2 +fluent_package_lts_version=5.0.5 + case ${code_name} in xenial) distribution=ubuntu diff --git a/fluent-package/apt/systemd-test/downgrade-to-v5.sh b/fluent-package/apt/systemd-test/downgrade-to-v5.sh new file mode 100755 index 000000000..50ac15e50 --- /dev/null +++ b/fluent-package/apt/systemd-test/downgrade-to-v5.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/../commonvar.sh + +# Install v5 LTS to register the repository +curl --fail --silent --show-error --location https://toolbelt.treasuredata.com/sh/install-${distribution}-${code_name}-fluent-package5-lts.sh | sh + +sudo apt purge -y fluent-package + +# Install the current +sudo apt install -V -y \ + /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +# Test: service status +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent +main_pid=$(eval $(systemctl show td-agent --property=MainPID) && echo $MainPID) + +# Downgrade to v5 LTS +apt install -V -y fluent-package=${fluent_package_lts_version}-1 --allow-downgrades + +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent + +# Fluentd should be restarted. +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) diff --git a/fluent-package/apt/systemd-test/update-from-v5.sh b/fluent-package/apt/systemd-test/update-from-v5.sh new file mode 100755 index 000000000..9baa72fba --- /dev/null +++ b/fluent-package/apt/systemd-test/update-from-v5.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/../commonvar.sh + + +# If it update from v5 LTS without stopping Fluentd, Fluentd will not be restarted. +# Install v5 LTS +curl --fail --silent --show-error --location https://toolbelt.treasuredata.com/sh/install-${distribution}-${code_name}-fluent-package5-lts.sh | sh + +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent +main_pid=$(eval $(systemctl show td-agent --property=MainPID) && echo $MainPID) + +# Install the current +sudo apt install -V -y \ + /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +# Test: service status +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent + +# Fluentd should NOT be restarted. +test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +apt purge -y fluent-package + +# If it update from v5 LTS with stopping Fluentd, Fluentd will be started when service is enabled. +# Install v5 LTS +curl --fail --silent --show-error --location https://toolbelt.treasuredata.com/sh/install-${distribution}-${code_name}-fluent-package5-lts.sh | sh + +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent +main_pid=$(eval $(systemctl show td-agent --property=MainPID) && echo $MainPID) + +systemctl stop fluentd + +# Install the current +sudo apt install -V -y \ + /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent + +# Fluentd should be started if service was stopped before update. +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Test: environmental variables +pid=$(systemctl show fluentd --property=MainPID --value) +env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ) +test $(eval $env_vars && echo $HOME) = "/var/lib/fluent" +test $(eval $env_vars && echo $LOGNAME) = "_fluentd" +test $(eval $env_vars && echo $USER) = "_fluentd" +test $(eval $env_vars && echo $FLUENT_CONF) = "/etc/fluent/fluentd.conf" +test $(eval $env_vars && echo $FLUENT_PACKAGE_LOG_FILE) = "/var/log/fluent/fluentd.log" +test $(eval $env_vars && echo $FLUENT_PLUGIN) = "/etc/fluent/plugin" +test $(eval $env_vars && echo $FLUENT_SOCKET) = "/var/run/fluent/fluentd.sock" + +# Test: No error logs +# (v5 default config outputs 'warn' log, so we should check only 'error' and 'fatal' logs) +sleep 3 +test -e /var/log/fluent/fluentd.log +(! grep -e '\[error\]' -e '\[fatal\]' /var/log/fluent/fluentd.log) + +# Test: Guard duplicated instance +(! sudo /usr/sbin/fluentd) +(! sudo /usr/sbin/fluentd -v) +sudo /usr/sbin/fluentd --dry-run diff --git a/fluent-package/yum/systemd-test/commonvar.sh b/fluent-package/yum/systemd-test/commonvar.sh index 9a847fd8a..234de734f 100755 --- a/fluent-package/yum/systemd-test/commonvar.sh +++ b/fluent-package/yum/systemd-test/commonvar.sh @@ -3,6 +3,7 @@ distribution=$(cat /etc/system-release-cpe | awk '{print substr($1, index($1, "o"))}' | cut -d: -f2) version=$(cat /etc/system-release-cpe | awk '{print substr($1, index($1, "o"))}' | cut -d: -f4) td_agent_version=4.5.2 +fluent_package_lts_version=5.0.5 case $distribution in amazon) diff --git a/fluent-package/yum/systemd-test/downgrade-to-v5.sh b/fluent-package/yum/systemd-test/downgrade-to-v5.sh new file mode 100755 index 000000000..a0dd8af01 --- /dev/null +++ b/fluent-package/yum/systemd-test/downgrade-to-v5.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/commonvar.sh + +# Install v5 LTS to register the repository +case $distribution in + amazon) + case $version in + 2023) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2023-fluent-package5-lts.sh | sh + ;; + 2) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2-fluent-package5-lts.sh | sh + ;; + esac + ;; + *) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package5-lts.sh | sh + ;; +esac + +sudo $DNF remove -y fluent-package + +# Install the current +sudo $DNF install -y \ + /host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm + +sudo systemctl enable --now fluentd +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent +main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Downgrade to v5 LTS +sudo $DNF downgrade -y fluent-package-${fluent_package_lts_version} + +# Test: take over enabled state +systemctl is-enabled fluentd + +# Test: service status +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent + +# Fluentd should be restarted. +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) diff --git a/fluent-package/yum/systemd-test/update-from-v5.sh b/fluent-package/yum/systemd-test/update-from-v5.sh new file mode 100755 index 000000000..b51b0959c --- /dev/null +++ b/fluent-package/yum/systemd-test/update-from-v5.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/commonvar.sh + +# If it update from v5 LTS without stopping Fluentd, Fluentd will be restarted. +# Install v5 LTS +case $distribution in + amazon) + case $version in + 2023) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2023-fluent-package5-lts.sh | sh + ;; + 2) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2-fluent-package5-lts.sh | sh + ;; + esac + ;; + *) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package5-lts.sh | sh + ;; +esac + +sudo systemctl enable --now fluentd +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent +main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Install the current +sudo $DNF install -y \ + /host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm + +# Test: take over enabled state +systemctl is-enabled fluentd + +# Test: service status +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent + +# Fluentd should be restarted when update from v5 LTS. +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Test: environmental variables +pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) +env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ) +test $(eval $env_vars && echo $HOME) = "/var/lib/fluent" +test $(eval $env_vars && echo $LOGNAME) = "fluentd" +test $(eval $env_vars && echo $USER) = "fluentd" +test $(eval $env_vars && echo $FLUENT_CONF) = "/etc/fluent/fluentd.conf" +test $(eval $env_vars && echo $FLUENT_PACKAGE_LOG_FILE) = "/var/log/fluent/fluentd.log" +test $(eval $env_vars && echo $FLUENT_PLUGIN) = "/etc/fluent/plugin" +test $(eval $env_vars && echo $FLUENT_SOCKET) = "/var/run/fluent/fluentd.sock" + +# Test: No error logs +# (v5 default config outputs 'warn' log, so we should check only 'error' and 'fatal' logs) +sleep 3 +test -e /var/log/fluent/fluentd.log +(! grep -e '\[error\]' -e '\[fatal\]' /var/log/fluent/fluentd.log) + +# Test: Guard duplicated instance +(! sudo /usr/sbin/fluentd) +(! sudo /usr/sbin/fluentd -v) +sudo /usr/sbin/fluentd --dry-run + +# Uninstall +sudo $DNF remove -y fluent-package +sudo systemctl daemon-reload + +getent passwd fluentd >/dev/null +getent group fluentd >/dev/null + +# `sudo systemctl daemon-reload` clears the service completely. +# (The result of `systemctl status` will be `unfound`) +# Note: RPM does not leave links like `@/etc/systemd/system/fluentd.service`. +# (Different from deb) + +(! systemctl status --no-pager td-agent) +(! systemctl status --no-pager fluentd)