Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 21st, 2010  |  syntax: Bash  |  size: 4.48 KB  |  views: 124  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2. #
  3. # $Id: jboss_init_slackware.sh 71252 2010-06-21 17:52:00Z gtl $
  4. #
  5. # JBoss 4.2.3.GA Control Script
  6. #
  7. # To use this script run it as root - it will switch to the specified user
  8. #
  9. # Here is a little (and extremely primitive) startup/shutdown script
  10. # for Slackware systems. It assumes that JBoss lives in /opt/java/jboss,
  11. # it's run by user 'jboss' and JDK binaries are in /opt/java/jdk/bin.
  12. # All this can be changed in the script itself.
  13. #
  14. # Either modify this script for your requirements or just ensure that
  15. # the following variables are set correctly before calling the script.
  16.  
  17. #define where jboss is - this is the directory containing directories log, bin, conf etc
  18. #commented out for testing purpose only, uncomment this line on production server
  19. #JBOSS_HOME=${JBOSS_HOME:-"/opt/java/jboss"}
  20. #uncommented for testing purpose only, comment this line on production server
  21. JBOSS_HOME=${JBOSS_HOME:-"/home/gtl/java/jboss-4.2.3.GA"}
  22.  
  23. #define the user under which jboss will run, or use 'RUNASIS' to run as the current user
  24. #commented out for testing purpose only, uncomment this line on production server
  25. #JBOSS_USER=${JBOSS_USER:-"jboss"}
  26. #uncommented for testing purpose only, comment this line on production server
  27. JBOSS_USER=${JBOSS_USER:-"gtl"}
  28.  
  29. #make sure java is in your path
  30. #commented out for testing purpose only, uncomment this line on production server
  31. #JAVAPTH=${JAVAPTH:-"/opt/java/jdk/bin"}
  32. #uncommented for testing purpose only, comment this line on production server
  33. JAVAPTH=${JAVAPTH:-"/home/gtl/java/jdk/bin"}
  34.  
  35. #configuration to use, usually one of 'minimal', 'default', 'all'
  36. JBOSS_CONF=${JBOSS_CONF:-"default"}
  37.  
  38. #if JBOSS_HOST specified, use -b to bind jboss services to that address
  39. #JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}
  40. #commented out for testing purpose only, uncomment this line on production server
  41. #JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b 0.0.0.0"}
  42. JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b 0.0.0.0"}
  43.  
  44. #define the script to use to start jboss
  45. JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR"}
  46.  
  47. if [ "$JBOSS_USER" = "RUNASIS" ]; then
  48.   SUBIT=""
  49. else
  50.   SUBIT="su - $JBOSS_USER -c "
  51. fi
  52.  
  53. if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
  54.   # ensure the file exists
  55.   touch $JBOSS_CONSOLE
  56.   if [ ! -z "$SUBIT" ]; then
  57.     chown $JBOSS_USER $JBOSS_CONSOLE
  58.   fi
  59. fi
  60.  
  61. if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
  62.   echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
  63.   echo "WARNING: ignoring it and using /dev/null"
  64.   JBOSS_CONSOLE="/dev/null"
  65. fi
  66.  
  67. #define what will be done with the console log
  68. JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}
  69.  
  70. JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
  71.  
  72. if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
  73.   export PATH=$PATH:$JAVAPTH
  74. fi
  75.  
  76. if [ ! -d "$JBOSS_HOME" ]; then
  77.   echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
  78.   exit 1
  79. fi
  80.  
  81. echo JBOSS_CMD_START = $JBOSS_CMD_START
  82.  
  83. function procrunning() {
  84.    procid=0
  85.    JBOSSSCRIPT=$(echo $JBOSSSH | awk '{print $1}' | sed 's/\//\\\//g')
  86.    for procid in `/sbin/pidof -x "$JBOSSSCRIPT"`; do
  87.        ps -fp $procid | grep "${JBOSSSH% *}" > /dev/null && pid=$procid
  88.    done
  89. }
  90.  
  91.  
  92. stop() {
  93.     pid=0
  94.     procrunning
  95.     if [ $pid = '0' ]; then
  96.         echo -n -e "\nNo JBossas is currently running\n"
  97.         exit 1
  98.     fi
  99.  
  100.     RETVAL=1
  101.  
  102.     # If process is still running
  103.  
  104.     # First, try to kill it nicely
  105.     for id in `ps --ppid $pid | awk '{print $1}' | grep -v "^PID$"`; do
  106.        if [ -z "$SUBIT" ]; then
  107.            kill -15 $id
  108.        else
  109.            $SUBIT "kill -15 $id"
  110.        fi
  111.     done
  112.  
  113.     sleep=0
  114.     while [ $sleep -lt 120 -a $RETVAL -eq 1 ]; do
  115.         echo -n -e "\nwaiting for processes to stop";
  116.         sleep 10
  117.         sleep=`expr $sleep + 10`
  118.         pid=0
  119.         procrunning
  120.         if [ $pid == '0' ]; then
  121.             RETVAL=0
  122.         fi
  123.     done
  124.  
  125.     # Still not dead... kill it
  126.  
  127.     count=0
  128.     pid=0
  129.     procrunning
  130.  
  131.     if [ $RETVAL != 0 ] ; then
  132.         echo -e "\nTimeout: Shutdown command was sent, but process is still running with PID $pid"
  133.         exit 1
  134.     fi
  135.  
  136.     echo
  137.     exit 0
  138. }
  139.  
  140. case "$1" in
  141. start)
  142.     cd $JBOSS_HOME/bin
  143.     if [ -z "$SUBIT" ]; then
  144.         eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
  145.     else
  146.         $SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &"
  147.     fi
  148.     ;;
  149. stop)
  150.     stop
  151.     ;;
  152. restart)
  153.     $0 stop
  154.     $0 start
  155.     ;;
  156. *)
  157.     echo "usage: $0 (start|stop|restart|help)"
  158. esac
clone this paste RAW Paste Data