diff --git a/THANKS.md b/THANKS.md index 2d261c6e..2a098d89 100644 --- a/THANKS.md +++ b/THANKS.md @@ -2,3 +2,4 @@ * Thanks to Paul Davis for contributing the enhanced Javascript indexing API. * Thanks to Adam Lofts for the performance boosting JSONDocumentAdapter et al. * Thanks to Santiago M. Mola for the termvector option. +* Thanks to Sam Bisbee. diff --git a/pom.xml b/pom.xml index 9bf8446c..56058ec3 100644 --- a/pom.xml +++ b/pom.xml @@ -165,6 +165,7 @@ true true + com.github.rnewson.couchdb.lucene.Main diff --git a/src/main/assembly/dist.xml b/src/main/assembly/dist.xml index 3502f37c..e83d23a3 100644 --- a/src/main/assembly/dist.xml +++ b/src/main/assembly/dist.xml @@ -6,45 +6,49 @@ + ${project.basedir} + /usr/share/doc/couchdb-lucene - ${project.basedir}/README* - ${project.basedir}/LICENSE* - ${project.basedir}/NOTICE* + README* + LICENSE* + NOTICE* + BREAKING_CHANGES* + TODO* + THANKS* - / - ${project.basedir}/src/main/bin/run + ${project.basedir}/src/main/bin/couchdb-lucene 755 /bin ${project.basedir}/src/main/conf/couchdb-lucene.ini 644 - /conf + /etc/couchdb-lucene ${project.basedir}/src/main/conf/log4j.xml 644 - /conf + /etc/couchdb-lucene ${project.basedir}/couchdb-external-hook.py 755 - /tools + /bin ${project.basedir}/src/main/tools/etc/init.d/couchdb-lucene 755 - /tools/etc/init.d/couchdb-lucene + /etc/init.d runtime - /lib + /lib/couchdb-lucene diff --git a/src/main/bin/couchdb-lucene b/src/main/bin/couchdb-lucene new file mode 100755 index 00000000..26832073 --- /dev/null +++ b/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 + diff --git a/src/main/bin/run b/src/main/bin/run deleted file mode 100644 index c4a210fe..00000000 --- a/src/main/bin/run +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -[ -z $CL_BASEDIR ] && CL_BASEDIR=`dirname "$0"` -cd $CL_BASEDIR/.. - -JAVA_OPTS="-server -Xmx1g" -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 diff --git a/src/main/conf/couchdb-lucene.ini b/src/main/conf/couchdb-lucene.ini index 23e8826e..09b6603f 100644 --- a/src/main/conf/couchdb-lucene.ini +++ b/src/main/conf/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 diff --git a/src/main/tools/etc/init.d/couchdb-lucene b/src/main/tools/etc/init.d/couchdb-lucene index d792a37d..5cf4033f 100644 --- a/src/main/tools/etc/init.d/couchdb-lucene +++ b/src/main/tools/etc/init.d/couchdb-lucene @@ -9,21 +9,23 @@ # Description: Initscript for CouchDB-Lucene ### END INIT INFO -# Author: Sebastian Cohnen -# - # 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 @@ -31,27 +33,22 @@ SCRIPTNAME=/etc/init.d/$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 } # @@ -59,102 +56,73 @@ do_start() # 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 :