forked from nicobrevin/jruby-jsvc
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some better instructions and a working example which hopefully corres…
…ponds to the README
- Loading branch information
Nick Griffiths
committed
Sep 6, 2010
1 parent
ebca99a
commit 2d65605
Showing
4 changed files
with
21 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## jruby-jsvc | ||
|
||
Run your jruby application as a unix daemon, taking advantage of the features you get in jsvc - http://commons.apache.org/daemon/ | ||
|
||
JSVC is the best way to run a java program (and hence jruby) as an init.d style daemon. Unfortunately, you can't fork in jruby like you would with MRI-ruby because the vm doesn't survive being forked (lots of important threads die). | ||
|
||
Using jsvc lets you can bring up your application in the foreground, check your db connection, ping a mail server or whatever your application needs to survive, possibly setuid (change user - jsvc options), before backgrounding it. | ||
|
||
## How to create a jruby-jsvc daemon | ||
|
||
1. Install jsvc-jruby. This consists of getting jsvc-jruby.jar and jsvc-wrapper.sh on to your system or in to your project folder. | ||
1. Take a look at `example/lib/crazy_daemon.rb` - you need to create a Daemon singleton module underneath your application's namespace, something like `Crazy::Daemon`. This should have a `setup?`, `start` and `stop` method. `setup?` should return true, and is basically a detection method to check that the daemon was defined and was able to bring up whatever resources it needed to be daemonic. `start` is called once the daemon has been backgrounded and is your signal to start accepting connections or chomping strings or whatever your application does. | ||
1. Create a boot-up script. This should require your daemon module and initialize your application so that it is ready to start serving once Daemon.start is called. | ||
1. Create an init.d script that invokes `jsvc-wrapper.bin` (or a copy of it). You'll need to set a few environment variables, and possibly tweak `jsvc-wrapper.sh` a bit. For development, you can call `jsvc-wrapper.sh` directly to test running your app as a daemon - Just invoke it from your applications root directory, with something like (works for the example application): | ||
|
||
JRUBY_JSVC_JAR=../target/jsvc-0.1.0.jar JRUBY_DAEMON_DEV=true MODULE_NAME=Crazy SCRIPT_NAME=daemon.rb ../bin/jsvc-wrapper.sh start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'lib/crazy_daemon.rb' | ||
|
||
Crazy::Daemon.init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters