@@ -9,8 +9,11 @@ status_before_update=$2 # active / inactive
99
1010install_current
1111
12+ sudo systemctl enable fluentd
13+
1214if [ " $status_before_update " = active ]; then
1315 sudo systemctl start fluentd
16+ main_pid=$( eval $( systemctl show fluentd --property=MainPID) && echo $MainPID )
1417fi
1518
1619# Set FLUENT_PACKAGE_SERVICE_RESTART
@@ -30,13 +33,81 @@ sudo $DNF install -y $package
3033# Show bundled ruby version
3134/opt/fluent/bin/ruby -v
3235
33- # Test: Check whether plugin/gem were installed during upgrading
34- if [ " $service_restart " != manual ] && [ " $status_before_update " = active ]; then
35- # plugin gem should be installed automatically
36- /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat
37- # Non fluent-plugin- prefix gem should not be installed automatically
38- (! /opt/fluent/bin/fluent-gem list | grep gqtp)
39- else
40- # plugin gem should not be installed automatically
36+ # Test: The service should take over the state
37+ systemctl is-enabled fluentd
38+
39+ if [ " $status_before_update " = inactive ]; then
40+ # Test: The service should NOT start automatically
41+ (! systemctl is-active fluentd)
42+ # Test: Plugin gem should not be installed automatically
4143 (! /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat)
44+ else
45+ # Test: The process before update should continue to run
46+ systemctl is-active fluentd
47+ test $main_pid -eq $( eval $( systemctl show fluentd --property=MainPID) && echo $MainPID )
48+
49+ sleep 15
50+
51+ if [ " $service_restart " = manual ]; then
52+ # Test: Plugin gem should not be installed automatically
53+ (! /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat)
54+ # Test: Main process should NOT be replaced until USR2 signal fired
55+ test $main_pid -eq $( eval $( systemctl show fluentd --property=MainPID) && echo $MainPID )
56+
57+ sudo kill -USR2 $main_pid
58+ sleep 15
59+
60+ # Test: Main process should be replaced by USR2 signal
61+ test $main_pid -ne $( eval $( systemctl show fluentd --property=MainPID) && echo $MainPID )
62+ else
63+ # Test: Plugin gem should be installed automatically
64+ /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat
65+ # Test: Non fluent-plugin- prefix gem should not be installed automatically
66+ (! /opt/fluent/bin/fluent-gem list | grep gqtp)
67+ # Test: Main process should be replaced automatically
68+ test $main_pid -ne $( eval $( systemctl show fluentd --property=MainPID) && echo $MainPID )
69+ fi
4270fi
71+
72+ # Ensure the service is started
73+ sudo systemctl start fluentd
74+
75+ # Test: migration process from v4 must not be done
76+ (! test -e /etc/td-agent)
77+ (! test -e /etc/fluent/td-agent.conf)
78+ (! test -e /var/log/td-agent)
79+ (! test -e /var/log/fluent/td-agent.log)
80+ (! test -h /usr/sbin/td-agent)
81+ (! test -h /usr/sbin/td-agent-gem)
82+
83+ # Test: environmental variables
84+ pid=$( eval $( systemctl show fluentd --property=MainPID) && echo $MainPID )
85+ env_vars=$( sudo sed -e ' s/\x0/\n/g' /proc/$pid /environ)
86+ test $( eval $env_vars && echo $HOME ) = " /var/lib/fluent"
87+ test $( eval $env_vars && echo $LOGNAME ) = " fluentd"
88+ test $( eval $env_vars && echo $USER ) = " fluentd"
89+ test $( eval $env_vars && echo $FLUENT_CONF ) = " /etc/fluent/fluentd.conf"
90+ test $( eval $env_vars && echo $FLUENT_PACKAGE_LOG_FILE ) = " /var/log/fluent/fluentd.log"
91+ test $( eval $env_vars && echo $FLUENT_PLUGIN ) = " /etc/fluent/plugin"
92+ test $( eval $env_vars && echo $FLUENT_SOCKET ) = " /var/run/fluent/fluentd.sock"
93+
94+ # Test: logs
95+ sleep 3
96+ test -e /var/log/fluent/fluentd.log
97+ (! grep -e ' \[warn\]' -e ' \[error\]' -e ' \[fatal\]' /var/log/fluent/fluentd.log)
98+
99+ # Uninstall
100+ sudo $DNF remove -y fluent-package
101+ sudo systemctl daemon-reload
102+
103+ (! getent passwd td-agent > /dev/null)
104+ (! getent group td-agent > /dev/null)
105+ getent passwd fluentd > /dev/null
106+ getent group fluentd > /dev/null
107+
108+ # `sudo systemctl daemon-reload` clears the service completely.
109+ # (The result of `systemctl status` will be `unfound`)
110+ # Note: RPM does not leave links like `@/etc/systemd/system/fluentd.service`.
111+ # (Different from deb)
112+
113+ (! systemctl status --no-pager fluentd)
0 commit comments