diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postinst b/fluent-package/templates/package-scripts/fluent-package/deb/postinst index 9e012b20..77bb10eb 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postinst @@ -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) diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/preinst b/fluent-package/templates/package-scripts/fluent-package/deb/preinst index 9a039afa..57b03462 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/preinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/preinst @@ -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 diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index 0617bbe4..f83cb4ca 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -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 @@ -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 @@ -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