Wednesday, April 4, 2012

JBoss system V init script


This script aims to provide a standardized approach to JBoss installations.
It can be used when you have multiple instances of Jboss application server on the same machine, and when you have several machines to administer.

The user used to run jboss is defined in the $JBOSS_USER variable, the java options - guess what? - are defined in the $JAVA_OPTS variable and you can append to the run.sh script using the $AFTER_RUN_SH variable.

Enjoy!

#!/bin/bash
#
# Script di start e stop JBOSS
# $Id$
# $HeadURL$

# Moreno Daltin 2011
# chkconfig: - 45 24
# description: jboss
#
# Moreno Daltin 2011



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

prog="jbossapp"

JBOSS_USER=jboss
export JBOSS_HOME=/home/jboss/jboss-epp-4.3/jboss-as/
export JAVA_HOME=/usr/java/jdk1.6.0_21
INSTANCE=app

AFTER_RUN_SH="-c $INSTANCE -b hostname"

export JAVA_OPTS="-XX:+UseParallelGC -XX:ParallelGCThreads=3 \
        -Xms2048M -Xmx2048M -XX:PermSize=128M -XX:MaxPermSize=256M \
        -Djava.net.preferIPv4Stack=true \
        -Dsun.rmi.dgc.client.gcInterval=1800000 \
        -Dsun.rmi.dgc.server.gcInterval=1800000 \
        -Djboss.messaging.ServerPeerID=1 \
        -Dorg.jboss.logging.Log4jService.catchSystemOut=true \
        -Dorg.jboss.logging.Log4jService.catchSystemErr=true \
        -Djgroups.bind_addr=hostname"



$STATUS=0

case "$1" in
  start)
        rm -rf $JBOSS_HOME/server/$INSTANCE/{tmp,work,data}
        su $JBOSS_USER -m -c "$JBOSS_HOME/bin/run.sh $AFTER_RUN_SH > $JBOSS_HOME/server/$INSTANCE/log/stdout 2> $JBOSS_HOME/server/$INSTANCE/log/stderr &"
        if [ $? == 0 ]
        then
                echo -n "Starting ..."
                success
        else
                echo -n "Failed"
                failure
        fi
        echo
;;
  stop)
        PID=`ps aux|grep java|grep -v grep|grep $INSTANCE | awk '{print $2}'`
        if [ "x$PID" != "x" ]
        then
                echo -n "Killing ..."
                kill $PID
                sleep 20
                PID=`ps aux|grep java|grep -v grep|grep $INSTANCE | awk '{print $2}'`
                if [ "x$PID" != "x" ]
                then
                        kill -9 $PID
                fi
                PID=`ps aux|grep java|grep -v grep|grep $INSTANCE | awk '{print $2}'`
                if [ "x$PID" != "x" ]
                then    
                        echo -n "Not killed"
                        failure
                else
                        success
                fi
        else
                echo -n "Already dead"
                success
        fi
        echo
        ;;
  status)
        PID=`ps aux|grep java|grep -v grep|grep $INSTANCE | awk '{print $2}'`
        if [ "x$PID" != "x" ]
        then
                echo -n "Running"
                success
        else
                echo -n "Dead"
                failure
                echo
                exit 1
        fi
        echo
        ;;
esac

1 comment:

  1. Caesars Palace casino opens today in Cotai - DRMCD
    CINCINNATI (CBSLA.com) 안전 바카라 사이트의정부 출장마사지 Caesars Palace Cotai, the only 경상남도 출장샵 Caesars Palace property in Cotai, opened 부천 출장샵 on Thursday. 하남 출장샵

    ReplyDelete