[pkg-jboss-commits] cvs commit to jboss3/debian by agx

pkg-jboss-commits@lists.alioth.debian.org pkg-jboss-commits@lists.alioth.debian.org
Sat, 15 May 2004 09:56:27 -0600


Update of /cvsroot/pkg-jboss/jboss3/debian
In directory haydn:/tmp/cvs-serv5609

Added Files:
	jboss3.default jboss3.init 
Log Message:
startup scripts

--- NEW FILE: jboss3.default ---
# Defaults for JBoss initscript (/etc/init.d/jboss3)
# This is a POSIX shell fragment

# Run JBoss this user ID (default: jboss). Set this to an empty string
# to prevent Tomcat from starting.
#JBOSS_USER=jboss

# The home directory of the Java development kit (JDK).
#JAVA_HOME=/usr/lib/j2sdk1.4

# Configuration layout to use
#JBOSS_SERVER=default

# Timeout in seconds for the shutdown procedure (default: 30). The Java
# processes will be killed if tomcat4 has not stopped until then.
#JBOSS_SHUTDOWN=30

--- NEW FILE: jboss3.init ---
#! /bin/sh -e
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian 
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#               addepted for jboss3 by Guido Guenther <agx@sigxcpu.org>
#               with parts borrowed from tomcat4s startup script
#
# Version:	$Id: jboss3.init,v 1.1 2004/05/15 15:56:24 agx Exp $
NAME=jboss3
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
JBOSS_HOME=/usr/share/$NAME
DESC="JBoss"
DEFAULT=/etc/default/$NAME
JBOSS_PID=/var/run/jboss/$NAME.pid
export JBOSS_PID
JBOSS_SHUTDOWN=30

# Run JBoss as this user ID
JBOSS_USER=jboss

test -f $DAEMON || exit 0

# the first existing directory is used for JAVA_HOME ,if JAVA_HOME isn't
# defined in $DEFAULT
JDK_DIRS="/usr/lib/j2sdk1.4 /usr/lib/j2se/1.4"

# Include jboss defaults if available
if [ -f $DEFAULT ] ; then
	. $DEFAULT
fi

if [ -z "$JBOSS_USER" ]; then
	echo "Not starting/stopping $DESC as configured (JBOSS_USER is"
	echo "empty in $DEFAULT)."
	exit 0
fi

if [ `id -u` -ne 0 ]; then
	echo "Not starting/stopping $DESC, you are not root."
	exit 1
fi

# Look for the right JVM to use
for jdir in $JDK_DIRS; do
	if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
		JAVA_HOME="$jdir"
	fi
done
export JAVA_HOME

[ -n "$JBOSS_SERVER" ] && STARTUP_OPTS="-c $JBOSS_SERVER"

JBOSS_START="$JBOSS_HOME/bin/run.sh"
JBOSS_STOP="$JBOSS_HOME/bin/shutdown.sh -S"


case "$1" in
  start)
	if [ -z "$JAVA_HOME" ]; then
		echo "Could not start $DESC because no Java Development Kit"
		echo "(JDK) was found. Please download and install JDK 1.4 or higher and set"
		echo "JAVA_HOME in $DEFAULT to the JDK's installation directory."
		exit 0
	fi
	echo -n "Starting $DESC using Java from $JAVA_HOME: "

	if start-stop-daemon --test --start --pidfile "$JBOSS_PID"   \
		--user $JBOSS_USER --startas "$JAVA_HOME/bin/java"   \
		>/dev/null; then

		# Bug: jboss needs the cwd writeable
  		cd /var/cache/$NAME/tmp
	        # -p preserves the environment (for $JAVA_HOME etc.)
	        # -s is required because jboss's login shell is /bin/false
	        su -p -s /bin/sh $JBOSS_USER \
			-c "$JBOSS_START $STARTUP_OPTS" \
			>> "/var/log/$NAME/$NAME.out" 2>&1
		cd -
	else
		echo "(already running)."
	fi
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
        if start-stop-daemon --test --start --pidfile "$JBOSS_PID" \
		--user "$JBOSS_USER" --startas "$JAVA_HOME/bin/java" \
		>/dev/null; then
		echo "(not running)."
        else
		if ! su -p -s /bin/sh $JBOSS_USER \
			-c "$JBOSS_STOP" \
			>> "/var/log/$NAME/$NAME.out" 2>&1; then
			# killing the "normal" way failed so kill java process right away"	
			echo "(failed)"
			JBOSS_SHUTDOWN=0
		fi
		# Fallback to kill the JVM process in case stopping didn't work
		sleep 1
		while ! start-stop-daemon --test --start \
			--pidfile "$JBOSS_PID" --user "$JBOSS_USER" \
			--startas "$JAVA_HOME/bin/java" >/dev/null; do
			sleep 1
			JBOSS_SHUTDOWN=`expr $JBOSS_SHUTDOWN - 1` || true
			if [ $JBOSS_SHUTDOWN -le 0 ]; then
				echo -n " (killing) "
				start-stop-daemon --stop --signal 9 --oknodo \
					--quiet --pidfile "$JBOSS_PID" \
					--user "$JBOSS_USER"
			fi
			echo -n "."
		done
		rm -f "$JBOSS_PID"
		echo "$NAME."
	fi
	;;
   status)
        if start-stop-daemon --test --start --pidfile "$JBOSS_PID"   \
		--user $JBOSS_USER --startas "$JAVA_HOME/bin/java" \
		>/dev/null; then

		if [ -f "$JBOSS_PID" ]; then
		    echo "$DESC is not running, but pid file exists."
		    exit 1
		else
		    echo "$DESC is not running."
		    exit 3
		fi
	else
		echo -n "$DESC is running with Java pid "
		cat "$JBOSS_PID"
		exit 0
	fi
        ;;
  restart|force-reload)
  	$0 stop
	sleep 1
	$0 start
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0