Browse files

Merge Sam Bisbee's startup work

  • Loading branch information...
1 parent a62fbb7 commit 0a8b9f41858460bc581a24b7b4dd5c7931d87e6e Robert Newson committed Dec 5, 2011
Showing with 188 additions and 144 deletions.
  1. +1 −0 THANKS.md
  2. +1 −0 pom.xml
  3. +14 −10 src/main/assembly/dist.xml
  4. +90 −0 src/main/bin/couchdb-lucene
  5. +0 −20 src/main/bin/run
  6. +1 −1 src/main/resources/couchdb-lucene.ini
  7. +81 −113 src/main/tools/etc/init.d/couchdb-lucene
View
1 THANKS.md
@@ -2,3 +2,4 @@
* Thanks to Adam Lofts for the performance boosting JSONDocumentAdapter et al.
* Thanks to Santiago M. Mola for the termvector option.
* Thanks to Joe Hillenbrand for adding default result limit to config.
+* Thanks to Sam Bisbee.
View
1 pom.xml
@@ -179,6 +179,7 @@
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+ <mainClass>com.github.rnewson.couchdb.lucene.Main</mainClass>
</manifest>
</archive>
</configuration>
View
24 src/main/assembly/dist.xml
@@ -6,17 +6,21 @@
</formats>
<fileSets>
<fileSet>
+ <directory>${project.basedir}</directory>
+ <outputDirectory>/usr/share/doc/couchdb-lucene</outputDirectory>
<includes>
- <include>${project.basedir}/README*</include>
- <include>${project.basedir}/LICENSE*</include>
- <include>${project.basedir}/NOTICE*</include>
+ <include>README*</include>
+ <include>LICENSE*</include>
+ <include>NOTICE*</include>
+ <include>BREAKING_CHANGES*</include>
+ <include>TODO*</include>
+ <include>THANKS*</include>
</includes>
- <outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<files>
<file>
- <source>${project.basedir}/src/main/bin/run</source>
+ <source>${project.basedir}/src/main/bin/couchdb-lucene</source>
<fileMode>755</fileMode>
<outputDirectory>/bin</outputDirectory>
</file>
@@ -28,28 +32,28 @@
<file>
<source>${project.basedir}/src/main/resources/couchdb-lucene.ini</source>
<fileMode>644</fileMode>
- <outputDirectory>/conf</outputDirectory>
+ <outputDirectory>/etc/couchdb-lucene</outputDirectory>
</file>
<file>
<source>${project.basedir}/src/main/resources/log4j.xml</source>
<fileMode>644</fileMode>
- <outputDirectory>/conf</outputDirectory>
+ <outputDirectory>/etc/couchdb-lucene</outputDirectory>
</file>
<file>
<source>${project.basedir}/couchdb-external-hook.py</source>
<fileMode>777</fileMode>
- <outputDirectory>/tools</outputDirectory>
+ <outputDirectory>/bin</outputDirectory>
</file>
<file>
<source>${project.basedir}/src/main/tools/etc/init.d/couchdb-lucene</source>
<fileMode>755</fileMode>
- <outputDirectory>/tools/etc/init.d/couchdb-lucene</outputDirectory>
+ <outputDirectory>/etc/init.d</outputDirectory>
</file>
</files>
<dependencySets>
<dependencySet>
<scope>runtime</scope>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>/lib/couchdb-lucene</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
View
90 src/main/bin/couchdb-lucene
@@ -0,0 +1,90 @@
+#!/bin/sh
+
+NAME="couchdb-lucene"
+BACKGROUND=false #whether to run in the background or not
+STDOUT_FILE="" #where to send background stdout to (defaults to &1)
+PID_FILE=/var/run/couchdb-lucene/couchdb-lucene.pid
+
+SCRIPT_OK=0
+SCRIPT_ERROR=1
+
+printUsage()
+{
+ cat << EOF
+Usage: `$basename $0` [OPTIONS]
+
+Starts the couchdb-lucene server component.
+
+Options:
+
+ -h displays this short help message and exits
+
+ -b spawn as a background process
+ -o FILE redirect background process's stdout to FILE (defaults to none)
+ -p FILE set the background process's PID FILE
+EOF
+}
+
+getPid()
+{
+ [ -f $PID_FILE ] && PID=`cat $PID_FILE`
+ echo $PID
+}
+
+start()
+{
+ CLASSPATH="$CL_BASEDIR/etc/couchdb-lucene:$CL_BASEDIR/lib/couchdb-lucene/*"
+ JAVA_OPTS="-server -Xmx1g -cp $CLASSPATH"
+
+ command="java $JAVA_OPTS $JAR com.github.rnewson.couchdb.lucene.Main"
+
+ if [ "$BACKGROUND" != "true" ]
+ then
+ eval $command
+ else
+ PID=`getPid`
+
+ if [ -z "$PID" ]
+ then
+ [ -n $STDOUT_FILE ] && command="$command >> $STDOUT_FILE"
+
+ eval "$command &"
+ echo $! > $PID_FILE
+ else
+ echo "$NAME is already running ($PID_FILE)."
+ fi
+ fi
+}
+
+checkEnvironment()
+{
+ prepend="couchdb-lucene needs write access to"
+ [ ! -w $STDOUT_FILE ] && echo "$prepend output file $STDOUT_FILE" && exit $SCRIPT_ERROR
+ unset prepend
+}
+
+parseOptions()
+{
+ opts=`getopt o:hbp: $@`
+ set -- $opts
+ while [ $# -gt 0 ]
+ do
+ case "$1" in
+ -h) shift; printUsage; exit $SCRIPT_OK;;
+ -o) shift; STDOUT_FILE="$1"; shift;;
+ -b) shift; BACKGROUND=true;;
+ -p) shift; PID_FILE="$1"; shift;;
+ --) shift; break;;
+ *) echo "Unknown option: $1" >&2; exit $SCRIPT_ERROR;;
+ esac
+ done
+}
+
+parseOptions $@
+checkEnvironment
+
+[ -z $CL_BASEDIR ] && CL_BASEDIR=`dirname "$0"`"/.."
+cd $CL_BASEDIR
+
+start
+
View
20 src/main/bin/run
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-[ -z $CL_BASEDIR ] && CL_BASEDIR=`dirname "$0"`
-cd $CL_BASEDIR/..
-
-JAVA_OPTS="-server -Xmx1g -XX:OnOutOfMemoryError=bin/kill_ppid"
-CLASS=com.github.rnewson.couchdb.lucene.Main
-
-CLASSPATH="conf"
-for JAR in `ls lib/*.jar`
-do
- CLASSPATH="$CLASSPATH:$JAR"
-done
-
-if [ -z $PIDFILE ]; then
- exec java $JAVA_OPTS -cp $CLASSPATH $CLASS
-else
- java $JAVA_OPTS -cp $CLASSPATH $CLASS &
- echo $! > $PIDFILE
-fi
View
2 src/main/resources/couchdb-lucene.ini
@@ -1,6 +1,6 @@
[lucene]
# The output directory for Lucene indexes.
-dir=indexes
+dir=/var/lib/couchdb-lucene/indexes
# The local host name that couchdb-lucene binds to
host=localhost
View
194 src/main/tools/etc/init.d/couchdb-lucene
@@ -9,152 +9,120 @@
# Description: Initscript for CouchDB-Lucene
### END INIT INFO
-# Author: Sebastian Cohnen <sebastian.cohnen@gmail.com>
-#
-
# Do NOT "set -e"
-PATH=/sbin:/usr/sbin:/bin:/usr/bin
-DESC="Description of the service"
+SCRIPT_OK=0
+SCRIPT_ERROR=1
+SCRIPT_ERROR_NOT_IMPLEMENTED=3
+SCRIPT_ERROR_NOT_INSTALLED=5
+
+DESC="CouchDB Lucene index"
NAME="couchdb-lucene"
-DAEMON=/usr/local/couchdb-lucene-0.5.5/bin/run
-PIDFILE=/var/run/$NAME.pid
-DAEMON_ARGS="$PIDFILE"
-SCRIPTNAME=/etc/init.d/$NAME
+PIDFILE=/var/run/$NAME/$NAME.pid
+DAEMON=$NAME
+DAEMON_ARGS="-o /var/log/couchdb-lucene.log -b -p $PIDFILE"
+SCRIPTNAME=`basename $0`
+LSB_LIBRARY=/lib/lsb/init-functions
# Exit if the package is not installed
-[ -x "$DAEMON" ] || exit 0
+[ -x "$DAEMON" ] || exit $SCRIPT_ERROR_NOT_INSTALLED
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
-# Define LSB log_* functions.
-# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
-. /lib/lsb/init-functions
+# We use LSB, so require that we can find the lib.
+[ ! -r $LSB_LIBRARY ] && echo "$NAME cannot find the LSB functions! Did you set LSB_LIBRARY?" && exit $SCRIPT_ERROR
+
+. $LSB_LIBRARY
#
# Function that starts the daemon/service
#
do_start()
{
- # Return
- # 0 if daemon has been started
- # 1 if daemon was already running
- # 2 if daemon could not be started
- PIDFILE=$PIDFILE start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
- || return 1
- PIDFILE=$PIDFILE start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- \
- $DAEMON_ARGS \
- || return 2
- # Add code here, if necessary, that waits for the process to be ready
- # to handle requests from services started subsequently which depend
- # on this one. As a last resort, sleep for some time.
+ # Return
+ # 0 if daemon has been started
+ # 1 if daemon was already running
+ # 2 if daemon could not be started
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test || return 1
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS || return 2
}
#
# Function that stops the daemon/service
#
do_stop()
{
- # Return
- # 0 if daemon has been stopped
- # 1 if daemon was already stopped
- # 2 if daemon could not be stopped
- # other if a failure occurred
- start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
- RETVAL="$?"
- [ "$RETVAL" = 2 ] && return 2
- # Wait for children to finish too if this is a daemon that forks
- # and if the daemon is only ever run from this initscript.
- # If the above conditions are not satisfied then add some other code
- # that waits for the process to drop all resources that could be
- # needed by services started subsequently. A last resort is to
- # sleep for some time.
- start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
- [ "$?" = 2 ] && return 2
- # Many daemons don't delete their pidfiles when they exit.
- rm -f $PIDFILE
- return "$RETVAL"
-}
-
-#
-# Function that sends a SIGHUP to the daemon/service
-#
-do_reload() {
- #
- # If the daemon can reload its configuration without
- # restarting (for example, when it is sent a SIGHUP),
- # then implement that here.
- #
- start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
- return 0
+ # Return
+ # 0 if daemon has been stopped
+ # 1 if daemon was already stopped
+ # 2 if daemon could not be stopped
+ # other if a failure occurred
+ start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
+ RETVAL="$?"
+ [ "$RETVAL" = 2 ] && return 2
+ # Wait for children to finish too if this is a daemon that forks
+ # and if the daemon is only ever run from this initscript.
+ # If the above conditions are not satisfied then add some other code
+ # that waits for the process to drop all resources that could be
+ # needed by services started subsequently. A last resort is to
+ # sleep for some time.
+ start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+ [ "$?" = 2 ] && return 2
+ # Many daemons don't delete their pidfiles when they exit.
+ rm -f $PIDFILE
+ return "$RETVAL"
}
case "$1" in
start)
- [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
- do_start
- case "$?" in
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
- esac
- ;;
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+ do_start
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+
stop)
- [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
- do_stop
- case "$?" in
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
- esac
- ;;
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+
status)
- #status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
- if [ ! -f $PIDFILE -o ! -d /proc/`cat $PIDFILE` ]
- then
- log_failure_msg "$NAME is not running"
- else
- log_success_msg "$NAME is running"
- fi
- ;;
- #reload|force-reload)
- #
- # If do_reload() is not implemented then leave this commented out
- # and leave 'force-reload' as an alias for 'restart'.
- #
- #log_daemon_msg "Reloading $DESC" "$NAME"
- #do_reload
- #log_end_msg $?
- #;;
+ status_of_proc "$DAEMON" "$NAME" && exit $SCRIPT_OK || exit $?
+ ;;
+
restart|force-reload)
- #
- # If the "reload" option is implemented then remove the
- # 'force-reload' alias
- #
- log_daemon_msg "Restarting $DESC" "$NAME"
- do_stop
- case "$?" in
- 0|1)
- do_start
- case "$?" in
- 0) log_end_msg 0 ;;
- 1) log_end_msg 1 ;; # Old process is still running
- *) log_end_msg 1 ;; # Failed to start
- esac
- ;;
- *)
- # Failed to stop
- log_end_msg 1
- ;;
- esac
- ;;
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1)
+ do_start
+ case "$?" in
+ 0) log_end_msg $SCRIPT_OK ;;
+ 1) log_end_msg $SCRIPT_ERROR ;; # Old process is still running
+ *) log_end_msg $SCRIPT_ERROR ;; # Failed to start
+ esac
+ ;;
+ *)
+ # Failed to stop
+ log_end_msg $SCRIPT_ERROR
+ ;;
+ esac
+ ;;
+
*)
- #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
- echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
- exit 3
- ;;
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit $SCRIPT_ERROR_NOT_IMPLEMENTED
+ ;;
esac
:

0 comments on commit 0a8b9f4

Please sign in to comment.