Skip to content

Commit

Permalink
Don't use the systemd plugin on JRuby (#3079)
Browse files Browse the repository at this point in the history
* 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 jruby/jruby#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
  • Loading branch information
mohamedhafez committed Feb 24, 2023
1 parent a61b078 commit 0fd1cc5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/puma/detect.rb
Expand Up @@ -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?)

Expand Down
5 changes: 4 additions & 1 deletion lib/puma/launcher.rb
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions test/helper.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_plugin_systemd.rb
Expand Up @@ -8,7 +8,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
Expand Down
27 changes: 27 additions & 0 deletions 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

0 comments on commit 0fd1cc5

Please sign in to comment.