File benno-rest.init of Package benno-rest

#! /bin/sh
# Copyright (c) 1995-2004 SuSE Linux AG, Nuernberg, Germany.
# Copyright (c) 2005 SUSE LINUX Products GmbH, Nuernberg, Germany.
# Copyright (c) 2012 Stefan Schaefer - FSP Computer & Netzwerke
# All rights reserved.
#
# Author: Stefan Schaefer - stefan.schaefer@fsproductions.de
#
## INFO Sektion bitte anpassen!
### BEGIN INIT INFO
# Provides: benno-rest
# Required-Start: $remote_fs $time
# Required-Stop: $remote_fs
# Should-Start: $syslog postfix
# Should-Stop: $syslog $time
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Short-Description: Start Service: ...
# Description:    Start Service: ...
### END INIT INFO

# Source SuSE config
. /etc/rc.status

SERVICE="benno-rest"

# Exit if components are not installed
SERVICE_BIN=/usr/bin/java
test -x $SERVICE_BIN || { echo "$SERVICE_BIN not installed";
    if [ "$1" = "stop" ]; then exit 0; else exit 5; fi; }

SERVICE_BASEDIR="/opt/benno"

SERVICE_JAR="$SERVICE_BASEDIR/bennorest.jar"

test -r $SERVICE_JAR || { echo "$SERVICE_JAR not existing";
    if [ "$1" = "stop" ]; then exit 0; else exit 6; fi; }

SERVICE_LOG="/var/log/benno/benno-rest_startup.log"

START_JAR="-jar $SERVICE_JAR"

LOG_CONFIG="/etc/benno/bennorest-log4j.xml"

SERVICE_PID=/var/run/$SERVICE.pid

# Umgebungsvariablen setzen
export LANG=C

# Read Configuration
[ -r /etc/default/$SERVICE ] && . /etc/default/$SERVICE

if [ "$START_ARCHIVE"x != "yes"x ]; then
                echo "$SERVICE disabled: not starting. To enable it edit /etc/default/$SERVICE"
                exit 0
fi

SERVICE_START_OPTS="-Dlog4j.configuration=$LOG_CONFIG $JAVA_OPTS$START_JAR $DAEMON_ARGS" > $SERVICE_LOG 2>&1

# User an Group to run service
SERVICE_UID="$USER"
SERVICE_GID="benno"

#
# Function that prints system info
#
do_info()
{
    (
        cd $SERVICE_BASEDIR
        su  -s /bin/sh \
            -c "$SERVICE_BIN \
                -Dlog4j.configuration=$LOG_CONFIG \
                $JAVA_OPTIONS \
                $START_JAR \
                $SERVICE_ARGS \
                --host-info" \
            $USER
    )
}

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - misc error
# 2 - invalid or excess args
# 3 - unimplemented feature (e.g. reload)
# 4 - insufficient privilege
# 5 - program not installed
# 6 - program not configured
#

case "$1" in
    start)
	echo -n "Starting Service: $SERVICE"
	/sbin/startproc -p $SERVICE_PID -u $SERVICE_UID -g $SERVICE_GID $SERVICE_BIN $SERVICE_START_OPTS
	
	# workaroud to create pid-file - startproc didn't work fine with java processes
	pid=`pgrep -f "$SERVICE_BIN $SERVICE_START_OPTS"`
	echo $pid > $SERVICE_PID
	
	rc_status -v
	;;
    stop)
	echo -n "Shutting down Service: $SERVICE"
	/sbin/killproc -p $SERVICE_PID -TERM $SERVICE_BIN
	# if nscd does not run as root, it cannot remove this files:
	rc_status -v
	;;
    restart)
	## Stop the service and regardless of whether it was
	## running or not, start it again.
	$0 stop
	# perhaps Sleep Time
	# sleep xy
	$0 start
	rc_status
	;;
    status)
	echo -n "Checking Service: $SERVICE"
	/sbin/checkproc -p $SERVICE_PID $SERVICE_BIN
	rc_status -v
	;;
    info)
	do_info
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|info}"
	exit 1
	;;
esac
rc_exit
openSUSE Build Service is sponsored by