File benno-archive.init of Package benno-archive

#! /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-archive
# Required-Start: $remote_fs $time 
# Required-Stop: $remote_fs
# Should-Start: $syslog postfix benno-rest
# 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-archive"

# 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/bennoarchive.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-archive_startup.log"

START_JAR="-jar $SERVICE_JAR"

LOG_CONFIG="/etc/benno/bennoarchive-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

# Network settings
SERVICE_ADDRESS="127.0.0.1"
SERVICE_PORT="2555"

SERVICE_START_OPTS="-Dlog4j.configuration=$LOG_CONFIG $JAVA_OPTS$START_JAR -b $SERVICE_ADDRESS -p $SERVICE_PORT $DAEMON_ARGS"

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

# 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 > $SERVICE_LOG 2>&1
	
	# 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
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
	;;
esac
rc_exit
openSUSE Build Service is sponsored by