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
psoutput - Build initd scripts that work properly and that your sys-admin will like
- Debian packaging
- Works on Windows, apparently :)
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 thecommons-daemonjar to be installed in to/usr/share/java/commons-daemon.jar. -
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 calledDaemonunderneath your application's namespace, something likeCrazy::Daemon. This should respond tosetup?,startandstopmethods. 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.