|
33 | 33 | %define v4migration_old_rotate_config_saved /tmp/@PACKAGE_DIR@/.old_rotate_config |
34 | 34 | %define v4migration_enabled_service /tmp/@PACKAGE_DIR@/.v4migration_enabled_service |
35 | 35 | %define local_base_plugins /tmp/@PACKAGE_DIR@/.local_base_plugins |
| 36 | +%define install_plugins /tmp/@PACKAGE_DIR@/.install_plugins |
| 37 | +%define pid_for_auto_restart /tmp/@PACKAGE_DIR@/.pid_for_auto_restart |
36 | 38 |
|
37 | 39 | # Omit the brp-python-bytecompile automagic because post hook for ffi fails on AmazonLinux 2. |
38 | 40 | %if %{_amazon_ver} == 2 |
@@ -160,6 +162,14 @@ mkdir -p %{buildroot}%{_sysconfdir}/@PACKAGE_DIR@/plugin |
160 | 162 | mkdir -p %{buildroot}/tmp/@PACKAGE_DIR@ |
161 | 163 |
|
162 | 164 | %pre |
| 165 | +# Make sure the previous tmp files for auto restart does not remain. |
| 166 | +# Note: |
| 167 | +# %preun (FROM-side) can create these files, but they will be removed in %posttrans (TO-side). |
| 168 | +# This means that these files may not be removed depending on the version of TO-side. |
| 169 | +# In the future, want to figure out a more secure way to manage tmp files... |
| 170 | +rm -f %{install_plugins} |
| 171 | +rm -f %{pid_for_auto_restart} |
| 172 | + |
163 | 173 | if ! getent group @COMPAT_SERVICE_NAME@ >/dev/null; then |
164 | 174 | if ! getent group @SERVICE_NAME@ >/dev/null; then |
165 | 175 | /usr/sbin/groupadd --system @SERVICE_NAME@ |
@@ -188,16 +198,35 @@ else |
188 | 198 | fi |
189 | 199 | fi |
190 | 200 | if [ $1 -eq 2 ]; then |
191 | | - . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ |
192 | | - echo "pre FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" |
193 | | - if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = auto ]; then |
194 | | - # collect installed gems during upgrading |
| 201 | + # Collect plugin-list. |
| 202 | + # Note: |
| 203 | + # This should be done in %preun(1) of FROM-side, but we have no choice but to do this here. |
| 204 | + # %preun(1) of FROM-side is executed after TO-side installs the files and replaces embedded Ruby. |
| 205 | + # So, this needs to be done before it. |
| 206 | + if [ -e /usr/sbin/fluent-gem ]; then |
195 | 207 | /usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose > %{local_base_plugins} |
196 | 208 | fi |
197 | 209 | fi |
198 | 210 |
|
199 | 211 | %preun |
200 | 212 | %systemd_preun @SERVICE_NAME@.service |
| 213 | +if [ $1 -eq 1 ]; then |
| 214 | + # systemctl ... --property=MainPID --value is available since systemd 230 or later. |
| 215 | + # thus for amazonlinux:2, it can not be used. |
| 216 | + pid="$(systemctl show "@SERVICE_NAME@" --property=MainPID | cut -d'=' -f2)" |
| 217 | + if [ "$pid" -eq 0 ]; then |
| 218 | + echo "Do not use auto restart because the service is not active" |
| 219 | + else |
| 220 | + . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ |
| 221 | + echo "FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" |
| 222 | + if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = auto ]; then |
| 223 | + # Present that FROM-side wants auto installing plugins and restarting. |
| 224 | + # Note: Wants to collect plugin-list here, but we need to do it in %pre (see comments in %pre). |
| 225 | + touch %{install_plugins} |
| 226 | + echo "$pid" > %{pid_for_auto_restart} |
| 227 | + fi |
| 228 | + fi |
| 229 | +fi |
201 | 230 |
|
202 | 231 | %post |
203 | 232 | %systemd_post @SERVICE_NAME@.service |
@@ -291,51 +320,9 @@ if [ -f "%{_sysconfdir}/prelink.conf" ]; then |
291 | 320 | %{__sed} -i"" %{_sysconfdir}/prelink.conf -e "/\/opt\/td-agent\/bin\/ruby/d" |
292 | 321 | fi |
293 | 322 | fi |
294 | | -if [ $1 -eq 2 ]; then |
295 | | - # install missing plugins during upgrading package |
296 | | - if [ -f %{local_base_plugins} ]; then |
297 | | - local_current_plugins=$(/usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose) |
298 | | - if ! grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins}; then |
299 | | - echo "No missing plugins to install" |
300 | | - else |
301 | | - if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then |
302 | | - echo "No network connectivity..." |
303 | | - else |
304 | | - grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins} | while read missing_gem |
305 | | - do |
306 | | - if ! /usr/sbin/fluent-gem install --no-document $missing_gem; then |
307 | | - echo "Can't install missing plugin automatically: please install $missing_gem manually." |
308 | | - fi |
309 | | - done |
310 | | - fi |
311 | | - fi |
312 | | - rm -f %{local_base_plugins} |
313 | | - fi |
314 | | -fi |
315 | 323 |
|
316 | 324 | %postun |
317 | | -if [ $1 -eq 1 ]; then |
318 | | - # Control service during upgrading |
319 | | - . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ |
320 | | - echo "postun FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" |
321 | | - if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "auto" ]; then |
322 | | - # systemctl ... --property=MainPID --value is available since systemd 230 or later. |
323 | | - # thus for amazonlinux:2, it can not be used. |
324 | | - pid=$(systemctl show fluentd --property=MainPID | cut -d'=' -f2) |
325 | | - if [ $pid -gt 0 ]; then |
326 | | - echo "Kick auto service upgrade mode to MainPID:$pid" |
327 | | - kill -USR2 $pid |
328 | | - else |
329 | | - # no running fluentd service |
330 | | - echo "Suppress auto service upgrade mode to MainPID:$pid" |
331 | | - fi |
332 | | - elif [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "manual" ]; then |
333 | | - echo "No need to restart service in manual mode..." |
334 | | - else |
335 | | - # no support for upgrading without downtime |
336 | | - %systemd_postun_with_restart @SERVICE_NAME@.service |
337 | | - fi |
338 | | -fi |
| 325 | +# Disable systemd_postun_with_restart to manage restart on the package side. |
339 | 326 | if [ $1 -eq 0 ]; then |
340 | 327 | # Uninstall |
341 | 328 | # Without this uninstall conditional guard block ($1 -eq 0), symlink |
@@ -400,6 +387,31 @@ if [ -f %{v4migration} ]; then |
400 | 387 | rm -f %{v4migration_with_restart} |
401 | 388 | fi |
402 | 389 | fi |
| 390 | +if [ -f %{install_plugins} ] && [ -f %{local_base_plugins} ]; then |
| 391 | + local_current_plugins=$(/usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose) |
| 392 | + if ! grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins}; then |
| 393 | + echo "No missing plugins to install" |
| 394 | + else |
| 395 | + if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then |
| 396 | + echo "No network connectivity..." |
| 397 | + else |
| 398 | + grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins} | while read missing_gem |
| 399 | + do |
| 400 | + if ! /usr/sbin/fluent-gem install --no-document $missing_gem; then |
| 401 | + echo "Can't install missing plugin automatically: please install $missing_gem manually." |
| 402 | + fi |
| 403 | + done |
| 404 | + fi |
| 405 | + fi |
| 406 | +fi |
| 407 | +rm -f %{install_plugins} |
| 408 | +rm -f %{local_base_plugins} |
| 409 | +if [ -f %{pid_for_auto_restart} ]; then |
| 410 | + pid=$(cat %{pid_for_auto_restart}) |
| 411 | + echo "Kick auto restart to MainPID:$pid" |
| 412 | + kill -USR2 $pid |
| 413 | + rm -f %{pid_for_auto_restart} |
| 414 | +fi |
403 | 415 |
|
404 | 416 | %files |
405 | 417 | %doc README.md |
|
0 commit comments