Skip to content

Commit

Permalink
deb: use auto/manual feature when old package supports (#738)
Browse files Browse the repository at this point in the history
This PR will allow to switch auto/manual restart settings with DEB
package even when Fluentd is running.

---------

Signed-off-by: Shizuo Fujita <[email protected]>
Signed-off-by: Daijiro Fukuda <[email protected]>
  • Loading branch information
Watson1978 authored and daipom committed Dec 6, 2024
1 parent 2f464db commit 1d937d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ sudo apt purge -y fluent-package

# Upgrade package with manual feature
sudo apt install -V -y $package
sudo systemctl enable --now fluentd
sed -i 's/=auto/=manual/' /etc/default/fluentd
# TODO: Clarify the specification of FLUENT_PACKAGE_SERVICE_RESTART environment variable
sudo systemctl restart fluentd
main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID)

sudo apt install -V -y ./next_version.deb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,17 @@ install_missing_plugins() {
fi
}

zero_downtime_restart_supported=/tmp/<%= package_dir %>/.zero_downtime_restart_supported
fluentd_auto_restart() {
if [ ! -e "$zero_downtime_restart_supported" ]; then
return
fi

if [ -d /run/systemd/system ]; then
pid=$(systemctl show <%= service_name %> --property=MainPID --value)
if [ $pid -ne 0 ]; then
env_vars=$(sed -e 's/\x0/\n/g' /proc/$pid/environ)
action=$(eval $env_vars && echo $FLUENT_PACKAGE_SERVICE_RESTART)
case "$action" in
. /etc/default/<%= service_name %>
case "$FLUENT_PACKAGE_SERVICE_RESTART" in
auto)
echo "Kick auto service upgrade mode to MainPID:$pid"
kill -USR2 $pid
Expand All @@ -188,6 +192,7 @@ fluentd_auto_restart() {
esac
fi
fi
rm -rf $zero_downtime_restart_supported
}

case "$1" in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,24 @@ migrate_local_plugins() {
/usr/sbin/fluent-gem list '^fluent-plugin-' --no-version --no-verbose > $local_base_plugins
}

zero_downtime_restart_supported_version="1.18.0"
zero_downtime_restart_supported=/tmp/<%= package_dir %>/.zero_downtime_restart_supported
check_version() {
printf '%s\n' "$zero_downtime_restart_supported_version" "$1" | sort --check=quiet --version-sort
}
check_whether_zero_downtime_restart_supported() {
current_version=$(/usr/sbin/fluentd --version | cut -d' ' -f 4)
if check_version $current_version; then
echo "Fluentd $current_version supports zero downtime restart."
mkdir -p /tmp/<%= package_dir %>
touch $zero_downtime_restart_supported
fi
}

case "$1" in
upgrade)
migrate_local_plugins
check_whether_zero_downtime_restart_supported
;;
abort-upgrade)
;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ sudo $DNF remove -y fluent-package

# Upgrade package with manual feature
sudo $DNF install -y $package
sed -i 's/=auto/=manual/' /etc/sysconfig/fluentd
# TODO: Clarify the specification of FLUENT_PACKAGE_SERVICE_RESTART environment variable
sudo systemctl enable --now fluentd
sed -i 's/=auto/=manual/' /etc/sysconfig/fluentd
main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID)

sudo $DNF install -y ./$next_package
Expand Down

0 comments on commit 1d937d2

Please sign in to comment.