-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpm: improve process timing for safety
Points * FROM-package just leaves tmp files if it supports the features. * TO-package trigger the features if there are those tmp files. * Thus, can ensure that both FROM and TO support the feature. * Make installing plugin and restarting the same condition. Before 1. to-pre(2): Collect plugin-list. 2. Install TO-package 3. to-post(2): Install plugin. 4. from-preun(1): Do nothing. 5. Uninstall FROM-package 6. from-postun(1): Install plugin and restart if need. After 1. to-pre(2): Do nothing. 2. Install TO-package 3. to-post(2): Do nothing. 4. from-preun(1): * Check auto or not. * Leave plugin-list and pid if need. 5. Uninstall FROM-package 6. from-postun(1): Disable `%systemd_postun_with_restart`. 7. to-posttrans: Install plugin and restart if need. Signed-off-by: Daijiro Fukuda <[email protected]>
- Loading branch information
Showing
1 changed file
with
41 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
%define v4migration_old_rotate_config_saved /tmp/@PACKAGE_DIR@/.old_rotate_config | ||
%define v4migration_enabled_service /tmp/@PACKAGE_DIR@/.v4migration_enabled_service | ||
%define local_base_plugins /tmp/@PACKAGE_DIR@/.local_base_plugins | ||
%define pid_for_auto_restart /tmp/@PACKAGE_DIR@/.pid_for_auto_restart | ||
|
||
# Omit the brp-python-bytecompile automagic because post hook for ffi fails on AmazonLinux 2. | ||
%if %{_amazon_ver} == 2 | ||
|
@@ -187,17 +188,24 @@ else | |
/usr/sbin/useradd --system --uid $TD_UID --gid $TD_GID --home-dir %{_localstatedir}/lib/@PACKAGE_DIR@ --shell /sbin/nologin --non-unique @SERVICE_NAME@ | ||
fi | ||
fi | ||
if [ $1 -eq 2 ]; then | ||
. %{_sysconfdir}/sysconfig/@SERVICE_NAME@ | ||
echo "pre FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" | ||
if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = auto ]; then | ||
# collect installed gems during upgrading | ||
/usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose > %{local_base_plugins} | ||
fi | ||
fi | ||
|
||
%preun | ||
%systemd_preun @[email protected] | ||
if [ $1 -eq 1 ]; then | ||
# systemctl ... --property=MainPID --value is available since systemd 230 or later. | ||
# thus for amazonlinux:2, it can not be used. | ||
pid="$(systemctl show "@SERVICE_NAME@" --property=MainPID | cut -d'=' -f2)" | ||
if [ "$pid" -eq 0 ]; then | ||
echo "Do not use auto restart because the service is not active" | ||
else | ||
. %{_sysconfdir}/sysconfig/@SERVICE_NAME@ | ||
echo "FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" | ||
if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = auto ]; then | ||
/usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose > %{local_base_plugins} | ||
echo "$pid" > %{pid_for_auto_restart} | ||
fi | ||
fi | ||
fi | ||
|
||
%post | ||
%systemd_post @[email protected] | ||
|
@@ -291,51 +299,9 @@ if [ -f "%{_sysconfdir}/prelink.conf" ]; then | |
%{__sed} -i"" %{_sysconfdir}/prelink.conf -e "/\/opt\/td-agent\/bin\/ruby/d" | ||
fi | ||
fi | ||
if [ $1 -eq 2 ]; then | ||
# install missing plugins during upgrading package | ||
if [ -f %{local_base_plugins} ]; then | ||
local_current_plugins=$(/usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose) | ||
if ! grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins}; then | ||
echo "No missing plugins to install" | ||
else | ||
if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then | ||
echo "No network connectivity..." | ||
else | ||
grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins} | while read missing_gem | ||
do | ||
if ! /usr/sbin/fluent-gem install --no-document $missing_gem; then | ||
echo "Can't install missing plugin automatically: please install $missing_gem manually." | ||
fi | ||
done | ||
fi | ||
fi | ||
rm -f %{local_base_plugins} | ||
fi | ||
fi | ||
|
||
%postun | ||
if [ $1 -eq 1 ]; then | ||
# Control service during upgrading | ||
. %{_sysconfdir}/sysconfig/@SERVICE_NAME@ | ||
echo "postun FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" | ||
if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "auto" ]; then | ||
# systemctl ... --property=MainPID --value is available since systemd 230 or later. | ||
# thus for amazonlinux:2, it can not be used. | ||
pid=$(systemctl show fluentd --property=MainPID | cut -d'=' -f2) | ||
if [ $pid -gt 0 ]; then | ||
echo "Kick auto service upgrade mode to MainPID:$pid" | ||
kill -USR2 $pid | ||
else | ||
# no running fluentd service | ||
echo "Suppress auto service upgrade mode to MainPID:$pid" | ||
fi | ||
elif [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "manual" ]; then | ||
echo "No need to restart service in manual mode..." | ||
else | ||
# no support for upgrading without downtime | ||
%systemd_postun_with_restart @[email protected] | ||
fi | ||
fi | ||
# Disable systemd_postun_with_restart to manage restart on the package side. | ||
if [ $1 -eq 0 ]; then | ||
# Uninstall | ||
# Without this uninstall conditional guard block ($1 -eq 0), symlink | ||
|
@@ -400,6 +366,30 @@ if [ -f %{v4migration} ]; then | |
rm -f %{v4migration_with_restart} | ||
fi | ||
fi | ||
if [ -f %{local_base_plugins} ]; then | ||
local_current_plugins=$(/usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose) | ||
if ! grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins}; then | ||
echo "No missing plugins to install" | ||
else | ||
if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then | ||
echo "No network connectivity..." | ||
else | ||
grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins} | while read missing_gem | ||
do | ||
if ! /usr/sbin/fluent-gem install --no-document $missing_gem; then | ||
echo "Can't install missing plugin automatically: please install $missing_gem manually." | ||
fi | ||
done | ||
fi | ||
fi | ||
rm -f %{local_base_plugins} | ||
fi | ||
if [ -f %{pid_for_auto_restart} ]; then | ||
pid=$(cat %{pid_for_auto_restart}) | ||
echo "Kick auto restart to MainPID:$pid" | ||
kill -USR2 $pid | ||
rm -f %{pid_for_auto_restart} | ||
fi | ||
|
||
%files | ||
%doc README.md | ||
|