From 239df490119ed9bcecbfdef66b3c39617318d1d8 Mon Sep 17 00:00:00 2001 From: Mohamed Hafez Date: Thu, 23 Feb 2023 22:51:48 -0800 Subject: [PATCH] Don't use the systemd plugin on JRuby (#3079) * Don't use the systemd plugin on JRuby The systemd integration will fail for JRuby at https://github.com/puma/puma/blob/e3d5794a7ebe47577ced4d4dfdd6a6cc969ded01/lib/puma/sd_notify.rb#L140, because JRuby doesn't support UNIX datagram sockets yet, and won't for a while. See https://github.com/jruby/jruby/issues/6504. So turning it off here, so that JRuby users can integrate with systemd on their own if they wish without errors. * Improved skipping systemd for JRuby Added a comment to explain the situation, and used Puma's JRuby detection method instead of re-coding it. * test that systemd plugin isn't loaded on JRuby * rename to test_plugin_systemd_jruby.rb, fix lint * rename test to test_systemd_plugin_not_loaded * make and use skip_unless :linux --- lib/puma/detect.rb | 2 ++ lib/puma/launcher.rb | 5 ++++- test/helper.rb | 2 ++ test/test_plugin_systemd.rb | 2 +- test/test_plugin_systemd_jruby.rb | 27 +++++++++++++++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 test/test_plugin_systemd_jruby.rb diff --git a/lib/puma/detect.rb b/lib/puma/detect.rb index 3a3d268341..7cbecef3ea 100644 --- a/lib/puma/detect.rb +++ b/lib/puma/detect.rb @@ -17,6 +17,8 @@ module Puma IS_WINDOWS = !!(RUBY_PLATFORM =~ /mswin|ming|cygwin/) || IS_JRUBY && RUBY_DESCRIPTION.include?('mswin') + IS_LINUX = !(IS_OSX || IS_WINDOWS) + # @version 5.2.0 IS_MRI = (RUBY_ENGINE == 'ruby' || RUBY_ENGINE.nil?) diff --git a/lib/puma/launcher.rb b/lib/puma/launcher.rb index 2aa21b970f..204d334ff2 100644 --- a/lib/puma/launcher.rb +++ b/lib/puma/launcher.rb @@ -59,7 +59,10 @@ def initialize(conf, launcher_args={}) @environment = conf.environment - if ENV["NOTIFY_SOCKET"] + # Load the systemd integration if we detect systemd's NOTIFY_SOCKET. + # Skip this on JRuby though, because it is incompatible with the systemd + # integration due to https://github.com/jruby/jruby/issues/6504 + if ENV["NOTIFY_SOCKET"] && !Puma.jruby? @config.plugins.create('systemd') end diff --git a/test/helper.rb b/test/helper.rb index 56d7ac4f66..c6f301445d 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -145,6 +145,7 @@ def skip_unless_signal_exist?(sig, bt: caller) def skip_if(*engs, suffix: '', bt: caller) engs.each do |eng| skip_msg = case eng + when :linux then "Skipped if Linux#{suffix}" if Puma::IS_LINUX when :darwin then "Skipped if darwin#{suffix}" if Puma::IS_OSX when :jruby then "Skipped if JRuby#{suffix}" if Puma::IS_JRUBY when :truffleruby then "Skipped if TruffleRuby#{suffix}" if TRUFFLE @@ -165,6 +166,7 @@ def skip_if(*engs, suffix: '', bt: caller) # called with only one param def skip_unless(eng, bt: caller) skip_msg = case eng + when :linux then "Skip unless Linux" unless Puma::IS_LINUX when :darwin then "Skip unless darwin" unless Puma::IS_OSX when :jruby then "Skip unless JRuby" unless Puma::IS_JRUBY when :windows then "Skip unless Windows" unless Puma::IS_WINDOWS diff --git a/test/test_plugin_systemd.rb b/test/test_plugin_systemd.rb index 8fe67332b4..1ddb54f030 100644 --- a/test/test_plugin_systemd.rb +++ b/test/test_plugin_systemd.rb @@ -7,7 +7,7 @@ class TestPluginSystemd < TestIntegration "{ 0/5 threads, 5 available, 0 backlog }" def setup - skip "Skipped because Systemd support is linux-only" if windows? || osx? + skip_unless :linux skip_unless :unix skip_unless_signal_exist? :TERM skip_if :jruby diff --git a/test/test_plugin_systemd_jruby.rb b/test/test_plugin_systemd_jruby.rb new file mode 100644 index 0000000000..46e9d60a60 --- /dev/null +++ b/test/test_plugin_systemd_jruby.rb @@ -0,0 +1,27 @@ +require_relative "helper" +require_relative "helpers/integration" + +class TestPluginSystemdJruby < TestIntegration + + THREAD_LOG = TRUFFLE ? "{ 0/16 threads, 16 available, 0 backlog }" : + "{ 0/5 threads, 5 available, 0 backlog }" + + def setup + skip_unless :linux + skip_unless :unix + skip_unless_signal_exist? :TERM + skip_unless :jruby + + super + + ENV["NOTIFY_SOCKET"] = "/tmp/doesntmatter" + end + + def test_systemd_plugin_not_loaded + cli_server "test/rackup/hello.ru" + + assert_nil Puma::Plugins.instance_variable_get(:@plugins)["systemd"] + + stop_server + end +end