#!/bin/sh -e # @configure_input@ # Copyright (C) 2007 Noah Slater . # This file is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # This file is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # You should have received a copy of the GNU General Public License along with # this file; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ### BEGIN INIT INFO # Provides: couchdb # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: CouchDB init script # Description: CouchDB init script for the database server. ### END INIT INFO SCRIPT_OK=0 SCRIPT_ERROR=1 DESCRIPTION="database server" NAME=couchdb SCRIPT_NAME=$(basename $0) COUCHDB=%bindir%/%couchdb_command_name% CONFIGURATION_FILE=%sysconfdir%/default/couchdb LSB_LIBRARY=/lib/lsb/init-functions if test ! -x $COUCHDB; then exit $SCRIPT_ERROR fi if test -r $CONFIGURATION_FILE; then . $CONFIGURATION_FILE fi log_daemon_msg () { # Dummy function to be replaced by LSB library. echo $@ } log_end_msg () { # Dummy function to be replaced by LSB library. if test "$1" != "0"; then echo "Error with $DESCRIPTION: $NAME" fi return $1 } if test -r $LSB_LIBRARY; then . $LSB_LIBRARY fi start_couchdb () { # Start CouchDB as a background process. command="$COUCHDB -b" if test -n "$COUCHDB_INI_FILE"; then command="$command -c $COUCHDB_INI_FILE" fi if test -n "$COUCHDB_PID_FILE"; then command="$command -p $COUCHDB_PID_FILE" fi if test -n "$COUCHDB_STDOUT_FILE"; then command="$command -o $COUCHDB_STDOUT_FILE" fi if test -n "$COUCHDB_STDERR_FILE"; then command="$command -e $COUCHDB_STDERR_FILE" fi if test -n "$COUCHDB_USER"; then if test -n "$COUCHDB_PID_FILE"; then touch $COUCHDB_PID_FILE chown $COUCHDB_USER $COUCHDB_PID_FILE fi if su $COUCHDB_USER -c "$command" > /dev/null; then return $SCRIPT_OK else return $SCRIPT_ERROR fi else if $command > /dev/null; then return $SCRIPT_OK else return $SCRIPT_ERROR fi fi } stop_couchdb () { # Stop the running CouchDB process. command="$COUCHDB -d" if test -n "$COUCHDB_PID_FILE"; then command="$command -p $COUCHDB_PID_FILE" fi if test -n "$COUCHDB_USER"; then if su $COUCHDB_USER -c "$command" > /dev/null; then return $SCRIPT_OK else return $SCRIPT_ERROR fi else if $command > /dev/null; then return $SCRIPT_OK else return $SCRIPT_ERROR fi fi } display_status () { # Display the status of the running CouchDB process. $COUCHDB -s } parse_script_option_list () { # Parse arguments passed to the script and take appropriate action. case "$1" in start) log_daemon_msg "Starting $DESCRIPTION: $NAME" if start_couchdb; then log_end_msg $SCRIPT_OK else log_end_msg $SCRIPT_ERROR fi ;; stop) log_daemon_msg "Stopping $DESCRIPTION: $NAME" if stop_couchdb; then log_end_msg $SCRIPT_OK else log_end_msg $SCRIPT_ERROR fi ;; restart|force-reload) log_daemon_msg "Restarting $DESCRIPTION: $NAME" if stop_couchdb; then if start_couchdb; then log_end_msg $SCRIPT_OK else log_end_msg $SCRIPT_ERROR fi else log_end_msg $SCRIPT_ERROR fi ;; status) display_status ;; *) cat << EOF >&2 Usage: $SCRIPT_NAME {start|stop|restart|force-reload|status} EOF exit $SCRIPT_ERROR ;; esac } parse_script_option_list $@