099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye#!/bin/sh
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Startup script for Apache Derby
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye#
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Software License Agreement (BSD License)
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye#
d47b7213b7d5cd8f5fc70757b746342924488cf8Trond Norbye# Copyright (c) 2011, Trond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# All rights reserved.
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye#
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Redistribution and use in source and binary forms, with or without
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# modification, are permitted provided that the following conditions are
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# met:
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye#
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# * Redistributions of source code must retain the above copyright
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# notice, this list of conditions and the following disclaimer.
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye#
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# * Redistributions in binary form must reproduce the above
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# copyright notice, this list of conditions and the following disclaimer
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# in the documentation and/or other materials provided with the
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# distribution.
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye#
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# * The names of the contributors may be used to endorse or promote
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# products derived from this software without specific prior written
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# permission.
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye#
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye### BEGIN INIT INFO
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Provides: derby
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Required-Start: $network $local_fs
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Required-Stop: $network $local_fs
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Default-Start: 2 3 4 5
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Default-Stop: 0 1 6
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Short-Description: start Apache Derby
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye### END INIT INFO
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye#
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# You may install the links by installing the file in /etc/init.d and
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# execute:
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# update-rc.d derby default
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye#
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Defaults
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond NorbyeDERBY_USER=opengrok
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond NorbyeDERBY_GROUP=opengrok
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond NorbyeDERBY_JVM_OPTIONS=
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond NorbyeDERBY_DATA_DIR=/var/opengrok/derby
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond NorbyeDERBY_JAR_DIR=/usr/lib/jvm/java-6-sun/db/lib
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond NorbyeDERBY_JAR=${DERBY_JAR_DIR}/derbynet.jar
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye# Reads config file (will override defaults above)
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye[ -r /etc/default/derby ] && . /etc/default/derby
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond NorbyePIDFILE=/var/run/derby.pid
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye. /lib/lsb/init-functions
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbyecase "$1" in
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye start)
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye log_daemon_msg "Starting Derby"
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye # exit unless we've got the jar file
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye test -f ${DERBY_JAR}
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye if [ $? -ne 0 ]
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye then
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye log_failure_msg "Missing file: ${DERBY_JAR}"
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye exit 1
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye fi
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye start-stop-daemon \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye --start \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye --chuid ${DERBY_USER}:${DERBY_GROUP} \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye --background \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye --make-pidfile \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye --pidfile $PIDFILE \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye --quiet \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye --exec /usr/bin/java \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye -- \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye ${DERBY_JVM_OPTIONS} \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye -Dderby.system.home=${DERBY_DATA_DIR} \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye -jar ${DERBY_JAR_DIR}/derbynet.jar \
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye start
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye if [ $? -ne 0 ]
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye then
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye log_end_msg 1
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye exit 1
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye fi
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye log_end_msg 0
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye ;;
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye stop)
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye log_daemon_msg "Stopping Derby"
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye start-stop-daemon --stop --quiet --pidfile $PIDFILE
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye log_end_msg 0
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye ;;
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye restart)
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye $0 stop
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye if [ $? -eq 0 ]
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye then
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye sleep 1
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye $0 start
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye fi
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye ;;
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye try-restart)
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye status_of_proc -p $PIDFILE /usr/bin/java Derby > /dev/null 2>&1
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye if [ $? -eq 0 ]
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye then
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye $0 restart
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye fi
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye ;;
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye reload|force-reload)
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye ;;
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye status)
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye status_of_proc -p $PIDFILE /usr/bin/java Derby
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye exit $?
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye ;;
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye *)
d47b7213b7d5cd8f5fc70757b746342924488cf8Trond Norbye echo "Usage: /etc/init.d/derby {start|stop|restart|try-restart|reload|force-reload|status}"
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye exit 1
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye ;;
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbyeesac
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbye
099386ae66a95e7edfed3088abb82bc1e78b6e7cTrond Norbyeexit 0