diff --git a/fluent-package/apt/systemd-test/install-newly.sh b/fluent-package/apt/systemd-test/install-newly.sh index 37216cef9..0779de975 100755 --- a/fluent-package/apt/systemd-test/install-newly.sh +++ b/fluent-package/apt/systemd-test/install-newly.sh @@ -28,6 +28,14 @@ sudo fluent-gem install fluent-plugin-concat /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp test $(find /tmp/ -name gem_local_list.output | xargs cat) = "fluent-plugin-concat" +# Test: Guard duplicated instance +if [ "$1" = "local" ]; then + # FIXME: until guard feature was released, skip v5 and lts. + (! sudo /usr/sbin/fluentd) + (! sudo /usr/sbin/fluentd -v) + sudo /usr/sbin/fluentd --dry-run +fi + sudo apt remove -y fluent-package case ${code_name} in diff --git a/fluent-package/apt/systemd-test/update-from-v4.sh b/fluent-package/apt/systemd-test/update-from-v4.sh index 36a2c5fcf..16926a770 100755 --- a/fluent-package/apt/systemd-test/update-from-v4.sh +++ b/fluent-package/apt/systemd-test/update-from-v4.sh @@ -84,6 +84,12 @@ sudo fluent-gem install fluent-plugin-concat /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp test $(find /tmp/ -name gem_local_list.output | xargs cat) = "fluent-plugin-concat" +# Test: Guard duplicated instance +(! sudo /usr/sbin/fluentd) +(! sudo /usr/sbin/td-agent) +(! sudo /usr/sbin/fluentd -v) +sudo /usr/sbin/fluentd --dry-run + # Uninstall sudo apt remove -y fluent-package (! systemctl status --no-pager td-agent) diff --git a/fluent-package/apt/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh b/fluent-package/apt/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh index e8cf5aa91..30f42bf92 100755 --- a/fluent-package/apt/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh +++ b/fluent-package/apt/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh @@ -80,6 +80,12 @@ sleep 3 test -e /var/log/fluent/fluentd.log (! grep -e '\[error\]' -e '\[fatal\]' /var/log/fluent/fluentd.log) +# Test: Guard duplicated instance +(! sudo /usr/sbin/fluentd) +(! sudo /usr/sbin/td-agent) +(! sudo /usr/sbin/fluentd -v) +sudo /usr/sbin/fluentd --dry-run + # Uninstall sudo apt remove -y fluent-package (! systemctl status --no-pager td-agent) diff --git a/fluent-package/apt/systemd-test/update-to-next-version.sh b/fluent-package/apt/systemd-test/update-to-next-version.sh index 31f5410c1..bda33fc68 100755 --- a/fluent-package/apt/systemd-test/update-to-next-version.sh +++ b/fluent-package/apt/systemd-test/update-to-next-version.sh @@ -49,6 +49,12 @@ sleep 3 test -e /var/log/fluent/fluentd.log (! grep -q -e '\[warn\]' -e '\[error\]' -e '\[fatal\]' /var/log/fluent/fluentd.log) +# Test: Guard duplicated instance +(! sudo /usr/sbin/fluentd) +(! sudo /usr/sbin/td-agent) +(! sudo /usr/sbin/fluentd -v) +sudo /usr/sbin/fluentd --dry-run + # Uninstall sudo apt remove -y fluent-package (! systemctl status --no-pager td-agent) diff --git a/fluent-package/templates/usr/sbin/fluentd.erb b/fluent-package/templates/usr/sbin/fluentd.erb index 8e3833a42..d261062c0 100755 --- a/fluent-package/templates/usr/sbin/fluentd.erb +++ b/fluent-package/templates/usr/sbin/fluentd.erb @@ -12,4 +12,39 @@ if ARGV.include?("--version") puts "fluent-package #{PACKAGE_VERSION} fluentd #{Fluent::VERSION} (#{FLUENTD_REVISION})" exit 0 end + +class DuplicateInstanceChecker + def running_fluentd? + IO.popen(["systemctl", "is-active", "fluentd"]) do |_io| + return true if _io.readlines.last.chomp == "active" + end + false + end + + def prevent_duplicate_launch? + unless running_fluentd? + return false + end + true + end +end + +if RUBY_PLATFORM =~ /linux/ + checker = DuplicateInstanceChecker.new + if checker.prevent_duplicate_launch? + unless ARGV.include?("-c") or ARGV.include?("--config") or ARGV.include?("--dry-run") + puts("Error: Can't start duplicate Fluentd instance with the default config.") + if ARGV.include?("-v") + puts("To take the version, please use '--version', not '-v' ('--verbose').") + end + puts </bin/fluentd" diff --git a/fluent-package/yum/systemd-test/install-newly.sh b/fluent-package/yum/systemd-test/install-newly.sh index 70e6c6168..46cf8402c 100755 --- a/fluent-package/yum/systemd-test/install-newly.sh +++ b/fluent-package/yum/systemd-test/install-newly.sh @@ -51,6 +51,10 @@ if [ $1 = "local" ]; then sudo $DNF install -y tar findutils sudo /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp test $(find /tmp/ -name gem_local_list.output | xargs cat) = "fluent-plugin-concat" + # FIXME: until guard feature was released, skip v5 and lts. + (! sudo /usr/sbin/fluentd) + (! sudo /usr/sbin/fluentd -v) + sudo /usr/sbin/fluentd --dry-run fi sudo $DNF remove -y fluent-package diff --git a/fluent-package/yum/systemd-test/update-from-v4.sh b/fluent-package/yum/systemd-test/update-from-v4.sh index 480e12df6..1593893e7 100755 --- a/fluent-package/yum/systemd-test/update-from-v4.sh +++ b/fluent-package/yum/systemd-test/update-from-v4.sh @@ -96,6 +96,12 @@ sudo fluent-gem install fluent-plugin-concat sudo /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp test $(find /tmp/ -name gem_local_list.output | xargs cat) = "fluent-plugin-concat" +# Test: Guard duplicated instance +(! sudo /usr/sbin/fluentd) +(! sudo /usr/sbin/td-agent) +(! sudo /usr/sbin/fluentd -v) +sudo /usr/sbin/fluentd --dry-run + # Uninstall sudo $DNF remove -y fluent-package sudo systemctl daemon-reload diff --git a/fluent-package/yum/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh b/fluent-package/yum/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh index 25b89a062..f18dabbb2 100755 --- a/fluent-package/yum/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh +++ b/fluent-package/yum/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh @@ -115,6 +115,12 @@ sudo fluent-gem install fluent-plugin-concat sudo /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp test $(find /tmp/ -name gem_local_list.output | xargs cat) = "fluent-plugin-concat" +# Test: Guard duplicated instance +(! sudo /usr/sbin/fluentd) +(! sudo /usr/sbin/td-agent) +(! sudo /usr/sbin/fluentd -v) +sudo /usr/sbin/fluentd --dry-run + # Uninstall sudo $DNF remove -y fluent-package (! systemctl status --no-pager td-agent) diff --git a/fluent-package/yum/systemd-test/update-to-next-version.sh b/fluent-package/yum/systemd-test/update-to-next-version.sh index 83c5573ae..10dd7ce57 100755 --- a/fluent-package/yum/systemd-test/update-to-next-version.sh +++ b/fluent-package/yum/systemd-test/update-to-next-version.sh @@ -73,6 +73,12 @@ sudo fluent-gem install fluent-plugin-concat sudo /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp test $(find /tmp/ -name gem_local_list.output | xargs cat) = "fluent-plugin-concat" +# Test: Guard duplicated instance +(! sudo /usr/sbin/fluentd) +(! sudo /usr/sbin/td-agent) +(! sudo /usr/sbin/fluentd -v) +sudo /usr/sbin/fluentd --dry-run + # Uninstall sudo $DNF remove -y fluent-package sudo systemctl daemon-reload