Skip to content

Commit

Permalink
deb rpm: install missing gems
Browse files Browse the repository at this point in the history
Before:

* missing fluent-plugin was installed

After:

* missing fluent-plugin was installed
* missing dependency gem was also installed

NOTE:

* if missing gem requires development packages to build it, it will
fail.
* fluent-diagtool depends on highly systemd service, so it is simple
just to use fluent-gem detecting missing gems.

Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
  • Loading branch information
kenhys committed Oct 23, 2024
1 parent 50ee0d5 commit 31a4348
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,37 +145,43 @@ migration_from_v4_post_process() {
fi
}

local_plugin_migration=/tmp/<%= package_dir %>/.local_plugin_migration
local_base_plugins=/tmp/<%= package_dir %>/.local_base_plugins
local_missing_plugins=/tmp/<%= package_dir %>/.local_missing_plugins
local_base_gems=/tmp/<%= package_dir %>/.local_base_gems
local_current_gems=/tmp/<%= package_dir %>/.local_current_gems
local_missing_gems=/tmp/<%= package_dir %>/.local_missing_gems
install_missing_plugins() {
if [ -f $local_plugin_migration ]; then
echo "Checking network connectivity..."
if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then
echo "Can't install missing plugins automatically, please install the following plugins manually."
cat $local_plugin_migration
else
echo "Install missing plugins automatically..."
/usr/sbin/fluent-gem list | grep fluent-plugin | cut -d' ' -f1 > $local_base_plugins
# NOTE: Do not install already bundled plugins
diff -u $local_base_plugins $local_plugin_migration | grep '^+fluent' | sed -e 's/\+//' > $local_missing_plugins
if [ -s $local_missing_plugins ]; then
cat $local_missing_plugins | xargs sudo /usr/sbin/fluent-gem install --no-document
else
echo "No need to install missing plugins..."
# Install missing gems (even though systemd is not available, it works)
mkdir -p /tmp/<%= package_dir %>
/usr/sbin/fluent-gem list | cut -d' ' -f1 > $local_current_gems
if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then
echo "No network connectivity..."
else
if [ -f $local_base_gems ]; then
# mark '-' as missing gems
# NOTE: possibility to install gems which is deprecated or not needed anymore.
diff -u $local_base_gems $local_current_gems | sed -e '1,2d' | grep '^-' | sed -e 's/^-//g' > $local_missing_gems
if [ -s $local_missing_gems ]; then
echo "Try to install the following gems:"
cat $local_missing_gems
while read gem
do
if ! /usr/sbin/fluent-gem install --no-document $gem; then
echo "Can't install missing gem automatically: please install $gem manually."
fi
done < $local_missing_gems
fi
rm -f $local_base_plugins
rm -f $local_missing_plugins
else
echo "No need to install missing gems..."
fi
rm -f $local_plugin_migration
rm -f $local_base_gems
fi
rm -f $local_current_gems
}

fluentd_auto_restart() {
if [ -d /run/systemd/system ]; then
pid=$(systemctl show <%= service_name %> --property=MainPID --value)
if [ $pid -ne 0 ]; then
env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ)
env_vars=$(sed -e 's/\x0/\n/g' /proc/$pid/environ)
action=$(eval $env_vars && echo $FLUENT_PACKAGE_SERVICE_RESTART)
case "$action" in
auto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@ set -e
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package.

local_plugin_migration=/tmp/<%= package_dir %>/.local_plugin_migration
local_base_gems=/tmp/<%= package_dir %>/.local_base_gems
migrate_local_plugins() {
# collect manually installed plugins
archive_path=$(sudo /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp | tail -n 1 | cut -d' ' -f10)
local_gem_output=$(echo $archive_path | sed -e 's/diagout-//' -e 's/.tar.gz//')/output/gem_local_list.output
if [ -f $local_gem_output ]; then
if [ -s $local_gem_output ]; then
# If there are missing plugins, mark path to it
cp $local_gem_output $local_plugin_migration
fi
fi
# collect list of gems
# fluent-diagtool depends on systemd, piuparts fails
/opt/fluent/bin/fluent-gem list | cut -d' ' -f1 > $local_base_gems
}

case "$1" in
Expand Down
58 changes: 22 additions & 36 deletions fluent-package/yum/fluent-package.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
%define v4migration_with_restart /tmp/@PACKAGE_DIR@/.v4migration_with_restart
%define v4migration_old_rotate_config_saved /tmp/@PACKAGE_DIR@/.old_rotate_config
%define v4migration_enabled_service /tmp/@PACKAGE_DIR@/.v4migration_enabled_service
%define local_plugin_migration /tmp/@PACKAGE_DIR@/.local_plugin_migration
%define local_base_plugins /tmp/@PACKAGE_DIR@/.base-plugins
%define local_base_gems /tmp/@PACKAGE_DIR@/.local_base_gems
%define local_current_gems /tmp/@PACKAGE_DIR@/.local_current_gems
%define local_missing_gems /tmp/@PACKAGE_DIR@/.local_missing_gems

# Omit the brp-python-bytecompile automagic because post hook for ffi fails on AmazonLinux 2.
%if %{_amazon_ver} == 2
Expand Down Expand Up @@ -189,23 +190,8 @@ else
fi
fi
if [ $1 -eq 2 ]; then
# collect manually installed plugins during upgrading
archive_path=$(sudo /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp | tail -n 1 | cut -d' ' -f10)
local_gem_output=$(echo $archive_path | sed -e 's/diagout-//' -e 's/.tar.gz//')/output/gem_local_list.output
if [ -f $local_gem_output ]; then
if [ -s $local_gem_output ]; then
# If there are missing plugins, mark path to it
echo "Detected missing plugins..."
cp $local_gem_output %{local_plugin_migration}
else
echo "Missing $local_gem_output"
fi
else
echo "Missing $local_gem_output to check locally installed plugins."
fi
rm -f $archive_path
archive_dir=$(echo $archive_path | sed -e 's/diagout-//' -e 's/.tar.gz//')
rm -rf $archive_dir
# collect installed gems during upgrading
/opt/fluent/bin/fluent-gem list | cut -d' ' -f1 > %{local_base_gems}
fi

%preun
Expand Down Expand Up @@ -324,27 +310,27 @@ if [ -f "%{_sysconfdir}/prelink.conf" ]; then
fi
if [ $1 -eq 2 ]; then
# install missing plugins during upgrading package
if [ -f %{local_plugin_migration} ]; then
echo "Checking network connectivity..."
curl --fail --silent -O https://rubygems.org/specs.4.8.gz
if [ $? -eq 0 ]; then
echo "Install missing plugins automatically..."
/usr/sbin/fluent-gem list | grep fluent-plugin | cut -d' ' -f1 > %{local_base_plugins}
# NOTE: Do not install already bundled plugins
diff -u %{local_base_plugins} %{local_plugin_migration} | grep '^+fluent' | sed -e 's/\+//' > %{local_missing_plugins}
if [ -s %{local_missing_plugins} ]; then
cat %{local_missing_plugins} | xargs sudo /usr/sbin/fluent-gem install --no-document
/usr/sbin/fluent-gem list | cut -d' ' -f1 > %{local_current_gems}
if [ -f %{local_base_gems} ]; then
diff -u %{local_base_gems} %{local_current_gems} | grep '^-' | sed -e 's/^-//g' > %{local_missing_gems}
if [ -s %{local_missing_gems} ]; then
echo "Try to install the following gems:"
cat %{local_missing_gems}
if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then
echo "No network connectivity..."
else
echo "No need to install missing plugins..."
echo "Install missing dependency gems..."
while read gem
do
if ! /usr/sbin/fluent-gem install --no-document $gem; then
echo "Can't install missing gem automatically, please install $gem manually."
fi
done < %{local_missing_gems}
fi
rm -f %{local_base_plugins}
rm -f %{local_missing_plugins}
else
echo "Can't install missing plugins automatically, please install the following plugins manually."
cat %{local_plugin_migration}
fi
rm -f %{local_plugin_migration}
rm -f %{local_missing_gems}
fi
rm -f %{local_current_gems}
fi

%postun
Expand Down

0 comments on commit 31a4348

Please sign in to comment.