Skip to content

Commit

Permalink
removed spoon dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Jan 8, 2013
1 parent 96dd5af commit 957cdc5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 30 deletions.
9 changes: 1 addition & 8 deletions README.md
@@ -1,14 +1,7 @@
Daemonizing JRuby script
========================

Turn a JRuby script into a init-d style daemon.

Prerequisite: spoon gem
-----------------------

```
gem install spoon
```
Turn a JRuby script into a init-d style daemon with `nohup` command.

Usage
-----
Expand Down
18 changes: 5 additions & 13 deletions __template__/service
Expand Up @@ -29,15 +29,6 @@ export GEM_PATH=
export GEM_HOME=

# ---------------------------------------------------
WRAPPER='
require "rubygems";
require "spoon";
pid = Spoon.spawnp(*ARGV[1..-1]);
File.open(ARGV[0], "w") { |f| f << pid };
'
SHIM=/tmp/${APP_NAME}_shim.rb
echo $WRAPPER > $SHIM
COMMAND="$JRUBY $SHIM '$PID_FILE' '$JRUBY' '$RUBY_SCRIPT' $ARGV"

start_daemon() {
if [ -e "$PID_FILE" ]; then
Expand All @@ -46,9 +37,11 @@ start_daemon() {
else
echo "Starting $APP_NAME."
if [ $LOGGING -eq 1 ]; then
eval $COMMAND 2>> $ERR_FILE >> $OUT_FILE
nohup $JRUBY $RUBY_SCRIPT $ARGV 2>> $ERR_FILE >> $OUT_FILE &
echo $! > "$PID_FILE"
else
eval $COMMAND
nohup $JRUBY $RUBY_SCRIPT $ARGV 2> /dev/null > /dev/null &
echo $! > "$PID_FILE"
fi
exit $?
fi
Expand All @@ -66,7 +59,7 @@ stop_daemon() {
rm $PID_FILE
else
echo "PID file not found."
exit 1
return 1
fi
}

Expand All @@ -87,5 +80,4 @@ case $1 in
exit 1
;;
esac
exit 0

15 changes: 6 additions & 9 deletions create-template
Expand Up @@ -15,15 +15,12 @@ if [ -e $1 ]; then
exit 1
fi

if [ -z "`which jruby`" ]; then
echo 'Cannot find `jruby` executable.'
exit 1
fi

if [ -z "`which gem`" ]; then
echo 'Cannot find `gem` executable.'
exit 1
fi
for cmd in jruby gem nohup; do
if [ -z "`which $cmd`" ]; then
echo "Cannot find '$cmd' executable."
exit 1
fi
done

NAME=`basename $1`
mkdir -p $1
Expand Down

0 comments on commit 957cdc5

Please sign in to comment.