Trying to use Foreman, getting a "invalid ruby runtime"

At a bit of a loss with this one.

jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (Java
HotSpot™ 64-Bit Server VM 1.7.0_05) [linux-amd64-java]
Installed with RVM.

Setting up a simple Procfile and Ruby code (just does a puts every 10
seconds) to run with Foreman, with plans to try and deploy it to Heroku
(just testing out how it all works).

I run “foreman start” and get the following error:

foreman start
LoadError: load error: posix_spawn_ext – java.lang.RuntimeException:
invalid ruby runtime
require at org/jruby/RubyKernel.java:991
require at
/home/mark/.rvm/rubies/jruby-1.7.0.preview1/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/posix-spawn-0.3.6/lib/posix/spawn.rb:2
require at org/jruby/RubyKernel.java:991
require at
/home/mark/.rvm/rubies/jruby-1.7.0.preview1/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/process.rb:1
chdir at org/jruby/RubyDir.java:466
run at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/process.rb:47
run at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/process.rb:46
upto at org/jruby/RubyInteger.java:139
spawn_processes at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/engine.rb:259
each at org/jruby/RubyArray.java:1611
spawn_processes at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/engine.rb:256
spawn_processes at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/engine.rb:255
start at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/engine.rb:45
send at org/jruby/RubyBasicObject.java:1786
send at org/jruby/RubyKernel.java:1990
start at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/cli.rb:40
run at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/thor-0.15.4/lib/thor/task.rb:27
invoke_task at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/thor-0.15.4/lib/thor/invocation.rb:120
dispatch at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/thor-0.15.4/lib/thor.rb:275
start at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/thor-0.15.4/lib/thor/base.rb:425
load at org/jruby/RubyKernel.java:1017
(root) at
/home/mark/.rvm/gems/jruby-1.7.0.preview1/bin/foreman:23

Honestly - not quite sure what to do here. Fairly new to J/Ruby, so is
it
even possible to run Foreman with JRuby? It looked like it was from the
source.

Any help would be appreciated!

Mark


E: [email protected]
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast

You get the “invalid ruby runtime” error when trying to use a library
containing C extensions under JRuby from more than one JRuby runtime.
Foreman depends on posix-spawn under JRuby, and posix-spawn has a native
component.

The real question is why are multiple JRuby runtimes involved when
running foreman start.

Ben

Thanks for your response, but I’m confused by some things.

If the issue is the posix-spawn having native extensions, how come it’s
only added as a dependency when the platform is Java:
https://github.com/ddollar/foreman/blob/master/foreman.gemspec#L22

Or are you saying that posix-spawn has somehow been installed with the
extensions, and therefore when I try and use it from JRuby, it all goes
pear shaped?

Thanks for your help!

Mark

On Tue, Jul 24, 2012 at 11:54 PM, Benjamin B.
[email protected]wrote:

On Jul 23, 2012, at 9:41 PM, Mark M. wrote:

      require at org/jruby/RubyKernel.java:991

spawn_processes at
start at
(root) at


E: [email protected]
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/

The posix-spawn dependency is only added under JRuby because reliably
spawning a subprocess and reading reading its output and error streams
is harder than you’d expect under JRuby.

So the author of foreman likely uses posix-spawn to not worry about
dealing with this directly, instead delegating those details to
posix-spawn. The issue is posix-spawn’s JRuby support still uses a C
extension. So, while it works under JRuby, it won’t work if it gets
loaded from more than one JRuby runtime within the same JVM which is
apparently what’s happening.

Ben

I just had a coworker who just has a plain JRuby install, and he tried
the
same thing - same error. So it doesn’t sound like it’s a bug regarding
RVM,
it sounds like a legitamate bug with foreman.

I think I’ll just submit a bug on Github, and see where that gets me.
Thanks for your help though!

Mark

On Wed, Jul 25, 2012 at 8:39 AM, Mark M. [email protected]
wrote:

Thanks for your help!

HotSpot™ 64-Bit Server VM 1.7.0_05) [linux-amd64-java]
invalid ruby runtime
chdir at org/jruby/RubyDir.java:466
spawn_processes at

/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/thor-0.15.4/lib/thor/invocation.rb:120

source.
W: www.compoundtheory.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/


E: [email protected]
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/

When I was referring to JRuby runtime below I mean that some code is
spinning up more than one instance of the org.jruby.Ruby class within
the same JVM. If you’re code is not doing this explicitly and foreman is
not doing this explicitly then it may be happening implicitly - if JRuby
detects a command that shells out to Ruby then by default I believe it
intercepts those commands and runs them in a new JRuby runtime within
the same JVM versus firing up a new JVM.

Ben

But I only have 1 JRuby runtime installed. So I don’t understand.

Or are you saying that something in my code is loading up JRuby more
than
once?

Mark

On Wed, Jul 25, 2012 at 9:49 AM, Benjamin B.
[email protected]wrote:

Or are you saying that posix-spawn has somehow been installed with the

containing C extensions under JRuby from more than one JRuby runtime.
At a bit of a loss with this one.

/home/mark/.rvm/rubies/jruby-1.7.0.preview1/lib/ruby/shared/rubygems/custom_require.rb:36

         each at org/jruby/RubyArray.java:1611
          run at


E: [email protected]
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/


E: [email protected]
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/

So I was looking into this further, and I think the issue about spinning
up
more than one instance of Jruby was fixed several versions back:
http://jira.codehaus.org/browse/JRUBY-5044

From the ticket, the following command works with no problem:

jruby --1.9 -e ‘x = spawn “jruby -e sleep”; p x’

This looks to be something else entirely different.

It looks to be falling over on this line:
https://github.com/rtomayko/posix-spawn/blob/master/lib/posix/spawn.rb#L2

Which leads me to believe it’s an issue with C extensions not working,
but
that is outside my area of expertise.

Mark

On Thu, Jul 26, 2012 at 8:24 AM, Mark M. [email protected]
wrote:

from more than one JRuby runtime within the same JVM which is apparently
https://github.com/ddollar/foreman/blob/master/foreman.gemspec#L22
[email protected]> wrote:

(just testing out how it all works).

/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/posix-spawn-0.3.6/lib/posix/spawn.rb:2

         upto at org/jruby/RubyInteger.java:139
         send at org/jruby/RubyKernel.java:1990
         load at org/jruby/RubyKernel.java:1017

http://www.2ddu.com/
2 Devs from Down Under Podcast
http://www.2ddu.com/


E: [email protected]
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/

Mark, have you tried adding -J-Djruby.launch.inproc=false to the command
line?

If that works, you can add jruby.launch.inproc=false to ~/.jrubyrc

So this is the code I was working with (I should have put that up in the
first place):
https://gist.github.com/6b2c9424e1ee22dcf186/5cfd4216f49c7330177c9e92d95ed8e99c52e7b3

It really is very simple.

Not sure what would be firing up another Jruby instance.

Mark

On Wed, Jul 25, 2012 at 10:29 PM, Benjamin B.
[email protected]wrote:

On Jul 24, 2012, at 7:53 PM, Mark M. wrote:

The posix-spawn dependency is only added under JRuby because reliably
Ben
extensions, and therefore when I try and use it from JRuby, it all goes

containing C extensions under JRuby from more than one JRuby runtime.
At a bit of a loss with this one.

/home/mark/.rvm/rubies/jruby-1.7.0.preview1/lib/ruby/shared/rubygems/custom_require.rb:36

         each at org/jruby/RubyArray.java:1611
          run at


E: [email protected]
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/

Thanks for your help all.

Found a much easier solution:
http://www.without-brains.net/blog/2011/09/21/using-foreman-to-run-jruby-with-rvm-and-mri/

Works a treat! :slight_smile:

Mark

On Thu, Aug 2, 2012 at 9:16 AM, Mark M. [email protected]
wrote:

If that works, you can add jruby.launch.inproc=false to ~/.jrubyrc

jruby --1.9 -e ‘x = spawn “jruby -e sleep”; p x’
that is outside my area of expertise.

[email protected]>
intercepts

Or are you saying that something in my code is loading up JRuby more

spawning a subprocess and reading reading its output and error
JRuby runtime within the same JVM which is apparently what’s
only added as a dependency when the platform is Java:
Mark

component.
jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (Java

/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/posix-spawn-0.3.6/lib/posix/spawn.rb:2

/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/process.rb:47

/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/engine.rb:256

/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/cli.rb:40

W: www.compoundtheory.com
T: http://www.twitter.com/neurotic
E: [email protected]
E: [email protected]
http://xircles.codehaus.org/manage_email
2 Devs from Down Under Podcast
http://www.2ddu.com/


E: [email protected]
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/

Just tried this - no go.

Although checking the wiki:
https://github.com/jruby/jruby/wiki/ConfiguringJRuby

It says it defaults to false anyway:

launch.inproc=[true, false]
Set in-process launching of e.g. system(‘ruby …’). Default is
false.

Thanks for the help never the less. Looks like this isn’t going to work
out
:frowning:

Mark

On Thu, Aug 2, 2012 at 8:39 AM, Wayne M. [email protected]
wrote:

http://jira.codehaus.org/browse/JRUBY-5044
https://github.com/rtomayko/posix-spawn/blob/master/lib/posix/spawn.rb#L2

So this is the code I was working with (I should have put that up in the

doing this explicitly then it may be happening implicitly - if JRuby
But I only have 1 JRuby runtime installed. So I don’t understand.

it works under JRuby, it won’t work if it gets loaded from more than
If the issue is the posix-spawn having native extensions, how come

HotSpot™ 64-Bit Server VM 1.7.0_05) [linux-amd64-java]
LoadError: load error: posix_spawn_ext – java.lang.RuntimeException:

/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/process.rb:46

/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/foreman-0.51.0-java/lib/foreman/engine.rb:255

/home/mark/.rvm/gems/jruby-1.7.0.preview1/gems/thor-0.15.4/lib/thor/task.rb:27

       (root) at

Mark

http://www.2ddu.com/
2 Devs from Down Under Podcast


E: [email protected]
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs