Use jsvc to run a jruby app as an init.d style daemon
Ruby Java Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Run your jruby application as a unix daemon, via jsvc. Works around the fact that you can't really fork from jruby/java with all the nice features you'd expect in a unix daemon.


  • Check your application has started properly before it is backgrounded.
  • Pidfiles!
  • Friendly process name for ps output
  • Build initd scripts that work properly and that your sys-admin will like
  • Debian packaging
  • Works on Windows, apparently :)

How to create a jruby-jsvc daemon

These instructions are aimed at someone using a debian based system, although you can use jruby-jsvc with any *nix that can run jsvc, you just need to delve a bit deeper.

There is a working example that can be installed as a debian package. It is very simple, but should give you a complete guide to how to deploy apps on to debian with jruby-jsvc.

  1. Install jsvc. Your system may come with it, or you may have to build it yourself from It isn't the most difficult thing to get running. By default, jruby-jsvc expects the jsvc excecutable to be on your path, and expects the commons-daemon jar to be installed in to /usr/share/java/commons-daemon.jar.

  2. Install jruby-jsvc. You can either check it out from source and build it, or install the debian packages from the downloads page.

  3. Take a look at example/lib/crazy_daemon.rb - you need to create an object called Daemon underneath your application's namespace, something like Crazy::Daemon. This should respond to setup?, start and stop methods. See comments in that file for details on the interface.

  4. Create a start-up script - the entry point in to your application. This should load your daemon module and initialize your application so that it is ready to start serving once Daemon.start is called. There are a couple of examples in example/bin - one which succeeds, the other fails (Demonstrating the DaemonInitException).

  5. Create an init.d script using the jruby-jsvc-initd command. Take a look at bin/ for an example. The jruby-jsvc-initd command has some help output to aid you.

  6. Start/stop the daemon with your init.d script. Crazy.