[jboss-dev-forums] [Other JBoss Development Design] - run.sh to launch JBoss in background

mazz@jboss.com do-not-reply at jboss.com
Thu Oct 5 14:38:08 EDT 2006


I want to write an init.d script with the typical start - stop options to start JBossAS.  I want to use the method of writing a pid file when started and killing the pid found in the file when stopping.

I do not want to use the "normal" shutdown mechanism to stop it because that assumes the JBoss instance has exposed its remote MBean interface (and I do not want to assume that).  Plus, I want to ensure it is killed, and using the "kill" command is as fool-proof as I need it to be.

I also want to be able to use run.sh to start the instance (I do not want to have to do all the work run.sh does - setting up the JVM, passing in arguments, worrying about all the cygwin - darwin things, etc. etc.).

But, if my init.d script starts run.sh, I cannot use $! in my init.d script as the pid file contents because $! is the pid of run.sh script process.  It is NOT the pid of the JBoss JVM instance itself.  If I then go to kill the run.sh process, it dies, but the JVM process does not.  Therefore, the init.d stop option does not work - it cannot stop the JBoss VM.

I would like to propose to make the following change to run.sh that would facilitate this.  This change is backwards compatible.  What this change does is - if I set the environment variable "LAUNCH_JBOSS_IN_BACKGROUND" and source run.sh, run.sh will export JBOSS_PID as the pid value of the JVM process.  My init.d script (the thing that sources run.sh) will be able to  write JBOSS_PID anywhere I want and thus later be able to use it to kill the JBoss VM.  Here is the change I propose (it only changes the bottom - I wrap the existing loop in an if-statement with the else clause running the VM in background):


  | if [ "x$LAUNCH_JBOSS_IN_BACKGROUND" = "x" ]; then
  | ### START - BELOW IS WHAT ALREADY EXISTS IN run.sh
  |    STATUS=10
  |    while [ $STATUS -eq 10 ]
  |    do
  |    # Execute the JVM
  |       "$JAVA" $JAVA_OPTS \
  |          -Djava.endorsed.dirs="$JBOSS_ENDORSED_DIRS" \
  |          -classpath "$JBOSS_CLASSPATH" \
  |          org.jboss.Main "$@"
  |       STATUS=$?
  |       # if it doesn't work, you may want to take a look at this:
  |       #    http://developer.java.sun.com/developer/bugParade/bugs/4465334.html
  |    done
  | ### END - ABOVE IS WHAT ALREADY EXISTS IN run.sh
  | else
  |    "$JAVA" $JAVA_OPTS \
  |       -Djava.endorsed.dirs="$JBOSS_ENDORSED_DIRS" \
  |       -classpath "$JBOSS_CLASSPATH" \
  |       org.jboss.Main "$@" &
  |    JBOSS_PID=$!
  |    export JBOSS_PID
  | fi
  | 

Its important to note that if you use this LAUNCH_JBOSS_IN_BACKGROUND feature, you have to "source" run.sh (you can't execute it from your init.d process because environment variables do not export up to a parent process - you have to ". run.sh" in order to get that exported environment variable into the shell that sourced run.sh).

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976386#3976386

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976386



More information about the jboss-dev-forums mailing list