diff --git a/README b/README deleted file mode 100644 index fa20e96..0000000 --- a/README +++ /dev/null @@ -1,15 +0,0 @@ -1# 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 foregroung, and then detach and possibly setuid (change user), before backgrounding it. - -## How to create a jruby-jsvc daemon - -1. Install jsvc-jruby -1. Create a Daemon singleton module underneath your application's namespace, something like DataChomper::Daemon. This should have a setup?, start and stop method. setup? should return true, and is basically a detection method. 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. - diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..983c61a --- /dev/null +++ b/README.markdown @@ -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 diff --git a/example/bin/daemon.rb b/example/bin/daemon.rb new file mode 100644 index 0000000..93f77d7 --- /dev/null +++ b/example/bin/daemon.rb @@ -0,0 +1,3 @@ +require 'lib/crazy_daemon.rb' + +Crazy::Daemon.init diff --git a/example/lib/crazy_daemon.rb b/example/lib/crazy_daemon.rb index 7792cae..9bc1a31 100644 --- a/example/lib/crazy_daemon.rb +++ b/example/lib/crazy_daemon.rb @@ -6,11 +6,11 @@ module Crazy module Daemon - def initialize + def init puts "Pretending to setup stuff I need, and bind to sockets, etc" @setup = true end - + def setup? @setup end @@ -29,9 +29,3 @@ def stop extend self end end - -# When we are evaluated, we are expected to initialize ourselves -# so that when start is called, we are all ready to start serving -# and going about our daemonic business -Crazy::Daemon.initialize -