Run your jruby application as a unix daemon, via
jsvc. Works around the fact that you
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.
- Friendly process name for
- 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.
Install jsvc. Your system may come with it, or you may have to build it yourself from http://commons.apache.org/daemon/. It isn't the most difficult thing to get running. By default, jruby-jsvc expects the
jsvcexcecutable to be on your path, and expects the
commons-daemonjar to be installed in to
Install jruby-jsvc. You can either check it out from source and build it, or install the debian packages from the downloads page.
Take a look at
example/lib/crazy_daemon.rb- you need to create an object called
Daemonunderneath your application's namespace, something like
Crazy::Daemon. This should respond to
stopmethods. See comments in that file for details on the interface.
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.startis called. There are a couple of examples in example/bin - one which succeeds, the other fails (Demonstrating the DaemonInitException).
Create an init.d script using the jruby-jsvc-initd command. Take a look at bin/make-debian-initd-files.sh for an example. The jruby-jsvc-initd command has some help output to aid you.
Start/stop the daemon with your init.d script. Crazy.