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