Jruby daemons

Anyone tried using something like jsvc to daemonize/background a jruby
script? (Daemon – Daemon : Java Service)

I’m on linux, so I can use start-stop-daemon, but the necessary -b
switch in this case implies some hoops to check whether it *actually *
started that I’d rather avoid. It’d be nice to use something like jsvc
that can wait to be sure things are working before returning.

I found a few threads from 2008 discussing making daemons, but the best
answer I’ve found (link below) seems to be “background & nohup”, which
has the same “so… did it start?” issues.
http://groups.google.com/group/jruby-users/browse_thread/thread/4126f3e426609a54/f8a110099d41462a?lnk=gst&q=daemonize#

I’ve used the tanuki java service wrapper

wrapper.tanukisoftware.org

but that might be more than you need?

Jay

On Thu, Jul 1, 2010 at 12:48 PM, Jeff W. [email protected]
wrote:

be sure things are working before returning.

I found a few threads from 2008 discussing making daemons, but the best
answer I’ve found (link below) seems to be “background & nohup”, which has
the same “so… did it start?” issues.

http://groups.google.com/group/jruby-users/browse_thread/thread/4126f3e426609a54/f8a110099d41462a?lnk=gst&q=daemonize#


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Yes, I do! I’ll paste you in what we’re using…

We’ve implemented the Daemon interface that jsvc tells you to. The
trick is to bring your app up in the init method and start serving in
the start method. This lets the daemon report whether it has worked or
not before it backgrounds.

Let me know if you struggle and I’ll see if I can get you an example.

Cheers,
Nick

On Thu, 2010-07-01 at 09:48 -0700, Jeff W. wrote:

that can wait to be sure things are working before returning.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Awesome, very encouraging.

So your Daemon interface implementation is just a java class you wrote
that executes your jruby script?
Or did you implement the Daemon interface in your jruby script too?

Seems likely either could work, but I’m a little uncertain of the
division of work between $RUBY_SCRIPT and the “yourapp-java.jar”
referenced in the classpath of your script.

Thanks.

Yeah, it is a bit naff having to maintain a java code base - I tried
compiling ruby code (I think you’ll need a java class to use with
jsvc-daemon) with the jruby compiler but the method signatures didn’t
look right when I inspected the bytecode, but I could have been doing
something wrong. We have some other java code anyway, so not a massive
problem for us, plus I’m ex-Java, so i get to feel nostalgic using maven
for a while :slight_smile:

Here is a gist of a java class similar to the one we use

It refers to a Daemon module, which offers the interface/API between
JRubyDaemon and our application(s). We run a bunch of different
daemons, so this is just a code re-use thing.

Time permitting, I should be able to create a generic version and host
it somewhere, so you won’t have to maintain your own java code as that
is a PITA for some.

Cheers
Nick

On Fri, 2010-07-02 at 10:19 -0700, Jeff W. wrote:

-----Original Message-----
trick is to bring your app up in the init method and start serving in


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email