Greetings,

Here is a Linux jboss init script that is the result
of a discussion on jBoss-User 02/05/2001-02/12/2001, under
the heading "Starting jBoss as a service on linux.
Marc Fleury asked me to post it here when it was finished.
Thanks to Michael Drew, Toby Allsopp, and Tom Cook for their help.


1. First, a variant to "run.sh", called "go.sh",
that allows the option to run jBoss in the background,
whch is how it gets run from the init script. In addition,
it does a simple test for a JDK version, since the "-server"
switch does not work for all versions( eg IBM).

2. Second, a jboss init script.

There are some differences between how jboss will run as a service,
and how jboss will run when started from a user's shell due to the
way jboss loads its classpath. When started from a shell it first adds
"run.jar" to the users $CLASSPATH. When started as a service this
classpath
will be empty. I have put a reminder in the init script to add special
classpath information should it be needed.

3. I also have an simple rpm.spec file for building jboss rpms,
and manual packages from the cvs repertory, if anyone is interested.
Apparent Roland Kaufman has also posted links on this list to 
similar work he has done. I haven't had time to look at his 
scripts and files, so I don't know If what I have
here is redundant.


Cheers,

Chris Albert


Thus, for "go.sh" , ommitting some details, including the jetty and
tomcat options found in run.sh of jBoss_FINAL-2.0.
######################################################
#GO.SH
######################################################
#!/bin/sh
#
#go.sh
# Shell script to start and stop the server

if [ -z "$JBOSS_HOME" ] ;  then
        export JBOSS_HOME=/usr/local/jboss
fi

if [ -z "$JAVA_HOME" ] ;  then
  JAVA=`which java`
  if [ -z "$JAVA" ] ; then
    echo "Cannot find JAVA. Please set your PATH."
    exit 1
  fi
  JAVA_BINDIR=`dirname $JAVA`
  JAVA_HOME=$JAVA_BINDIR/..

if [ "$JAVACMD" = "" ] ; then
    if [ -d ${JAVA_HOME}/lib/i386 ] ; then
   # We are probably in a SUN/Blackdown environment ...
   JAVACMD="$JAVA_HOME/bin/java -server"
    else
   # it is probably Big Blue ...
   JAVACMD=$JAVA_HOME/bin/java
    fi
fi

# Minimal jar file to get JBoss started.
CLASSPATH=$CLASSPATH:$JBOSS_HOME/bin/run.jar
#next line for jBoss_FINAL-2.0
CLASSPATH="$CLASSPATH:$JBOSS_HOME/lib/jdbc2_0-stdext.jar:$JBOSS_HOME/lib/jboss-jaas.jar"

if [ "$1" = "start" ] ; then
  shift
  $JAVACMD $JBOSS_OPTS -classpath $CLASSPATH org.jboss.Main "$@" >
/dev/null 2>&1 &
  echo $! > /var/run/jboss.pid

elif [ "$1" = "stop" ] ; then
  shift
  kill -15 `cat /var/run/jboss.pid`
  rm -rf /var/run/jboss.pid

elif [ "$1" = "run" ] ; then
  shift
  $JAVACMD $JBOSS_OPTS -classpath $CLASSPATH   org.jboss.Main "$@"

else
  echo "Usage:"
  echo "jboss (start|run|stop)"
  echo "        start - start jboss in the background"
  echo "        run   - start jboss in the foreground"
  echo "        stop  - stop jboss"

  exit 0
fi
##################################################
#END GO.SH
##################################################

##################################################
# JBOSS.INIT
##################################################

#!/bin/sh
#
# Startup script for JBOSS, the J2EE EJB Server
#
# chkconfig: 2345 85 15
# description: Jboss is an EJB Server
# processname: jboss
# pidfile: /var/run/jboss.pid
# config: ${JBOSS_HOME}/conf/default/jboss.conf
# logfile: ${JBOSS_HOME}/log/server.log
#
#
# version 1.0 -
#

# Source function library.
. /etc/rc.d/init.d/functions

#SET THE FOLLOWING LINE TO YOUR JAVA_HOME 
export JAVA_HOME=/opt/jdk
#export JAVA_HOME=/usr/java/jdk1.3  #SUN's rpm
#export JAVA_HOME=/opt/IBMJava2-13  #IBM's rpm

#SET THE FOLLOWING LINE TO YOUR CORRECT JBOSS_HOME 
export JBOSS_HOME=/usr/local/jboss

export PATH=$PATH:$JBOSS_HOME/bin:$JAVA_HOME/bin:$JAVA_HOME/jre/bin

#IF YOU NEED SPECIAL CLASSES IN YOUR CLASSPATH
#AT STARTUP, ADD THEM TO YOUR CLASSPATH HERE
#export CLASSPATH=

RETVAL=0

# See how we were called.
case "$1" in
  start)
        cd $JBOSS_HOME/bin
        echo -n "Starting jboss daemon: "
        daemon $JBOSS_HOME/bin/run.sh start
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/jboss
        ;;
  stop)
        echo -n "Stopping jboss daemon: "
        killproc jboss
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/jboss
        ;;
  restart)
        echo -n "Restarting jboss daemon: "
 $0 stop
 sleep 2
 $0 start
        ;;

##############################################
#END JBOSS.INIT
##############################################


Reply via email to