Jboss Standalone script snippets

Below are some of the use full Jboss standalone script snippets .

add-user.sh
#!/bin/sh

ABSOLUTE_PATH="$(cd $(dirname "$0") && pwd -P)"
PROFILE_PATH="${ABSOLUTE_PATH%/*}"
DIR_NAME="${PROFILE_PATH##*/}"	# bin dir
#DIR_NAME="${ABSOLUTE_PATH##*/}"	# root dir

. $ABSOLUTE_PATH/jboss.env

JAVA_OPTS="$JAVA_OPTS -Djboss.server.config.user.dir=$SERVER_BASE_DIR/configuration "

#$JBOSS_HOME/bin/add-user.sh $@
$JBOSS_HOME/bin/add-user.sh
heapdump.sh

#!/bin/sh

ABSOLUTE_PATH="$(cd $(dirname "$0") && pwd -P)"
PROFILE_PATH="${ABSOLUTE_PATH%/*}"
DIR_NAME="${PROFILE_PATH##*/}"	# bin dir
#DIR_NAME="${ABSOLUTE_PATH##*/}"	# root dir

. $ABSOLUTE_PATH/jboss.env

PID=`ps -ef | grep java | grep "NODE_NAME=$NODE_NAME" | grep "jboss.server.base.dir=$SERVER_BASE_DIR" | awk '{print $2}'`
echo "PID:$PID"

if [ "$PID" == "" ]
then
    echo "$NODE_NAME is not running";
    exit 1;
fi

echo "jmap -dump:live,format=b,file=$PID-heapdump-$DATE.bin $PID"
jmap -dump:live,format=b,file=$PID-heapdump-$DATE.bin $PID
# EOF
jboss.env

DATE=`date "+%Y%m%d_%H%M%S"`
UNAME=`id -u -n`
JBOSS_USER="jboss"
NODE_NAME="sample"
##################################################
# JBOSS Common Setup
##################################################
JBOSS_HOME="/app/jboss"
SERVER_HOME="$JBOSS_HOME/SERVERS"
SERVER_BASE_DIR="$SERVER_HOME/$NODE_NAME"
SERVER_BIN_DIR="$SERVER_BASE_DIR/bin"
LOG_HOME="$SERVER_BASE_DIR/logs"

BIND_ADDR="192.168.2.71"
MGNT_ADDR="192.168.2.71"
PRIVATE_ADDR="192.168.2.71"
UNSECURE_ADDR="127.0.0.1"

MULTICAST_ADDR="230.0.0.3"
CLUSTER_PASSWD="CHANGEME!!"
MESSAGE_ADDR="231.7.10.1"
MESSAGE_PORT="9876"

MGNT_HTTP_PORT="9990"
MGNT_HTTPS_PORT="9993"

PORT_OFFSET="0"
PORT_AJP="8009"
PORT_HTTP="8080"
PORT_HTTPS="8443"

##################################################
# Current Host Setup
##################################################
GC_TYPE="g1"		# "cms", "parallel", "g1"(only jdk 7u4 or greater)
USE_LARGEPAGE="false"	# "true", "false"

##################################################
# Configration File
##################################################
SERVER_CONFIG_FILE="standalone-ha.xml"
##################################################
# Java Version Check
JAVA_VER=`java -version 2>&1 | sed 's/.*\?"\(.*\)".*/\1/; 1q'`
JAVA_VER_MAJOR=`java -version 2>&1 | sed 's/.*\?"\([0-9]*\)\..*".*/\1/; 1q'`
JAVA_VER_MINOR=`java -version 2>&1 | sed 's/.*\?"[0-9]*\.\([0-9]*\)\..*/\1/; 1q'`

if [ -z "$JAVA_VER" ]
then
        echo "Java is not installed"
        exit 1
fi
##################################################
# JVM Options
##################################################
JAVA_OPTS="-DNODE_NAME=$NODE_NAME"
JAVA_OPTS="$JAVA_OPTS -server"
JAVA_OPTS="$JAVA_OPTS -XX:+DoEscapeAnalysis"
JAVA_OPTS="$JAVA_OPTS -Xms2048m"
JAVA_OPTS="$JAVA_OPTS -Xmx4096m"

### Garbage Collection Options
JAVA_OPTS="$JAVA_OPTS -verbose:gc"
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
JAVA_OPTS="$JAVA_OPTS -XX:HeapDumpPath=$LOG_HOME/"

# Use on x86_64
JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedOops"

### Collector type : CMS(low pause)
if [ $GC_TYPE == "cms" ]; then
	JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"			         
	JAVA_OPTS="$JAVA_OPTS -XX:+CMSClassUnloadingEnabled"		         
	JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC"				         
	JAVA_OPTS="$JAVA_OPTS -XX:+ExplicitGCInvokesConcurrent"		         
	JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=80"	         
	JAVA_OPTS="$JAVA_OPTS -XX:CMSIncrementalSafetyFactor=20"	         
	JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly"	         

### Collector type : Parallel (throughput)
elif [ $GC_TYPE == "parallel" ]; then
	JAVA_OPTS="$JAVA_OPTS -XX:+UseParallelGC"
	JAVA_OPTS="$JAVA_OPTS -XX:+UseParallelOldGC"

### Collector type : G1 (low pause) ONLY USE for JDK 7u4 or greater
elif [ $GC_TYPE == "g1" ]; then
	JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC"
	JAVA_OPTS="$JAVA_OPTS -XX:+ExplicitGCInvokesConcurrent"
	JAVA_OPTS="$JAVA_OPTS -XX:MaxGCPauseMillis=500"
else
	echo "ERROR: GC_TYPE is NOT SET!!!";
	exit 0;
fi
###########################
# Setting for JVM Versions
if [ $JAVA_VER_MAJOR -ge 11 ]; then
        JAVA_OPTS="$JAVA_OPTS -Xlog:gc*:file=$LOG_HOME/gc-%p-%t.log:tags,uptime,time,level:filecount=10,filesize=50m"
else
        JAVA_OPTS="$JAVA_OPTS -Xloggc:$LOG_HOME/gc_$DATE.log"
        JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails"
        JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps"
        JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCApplicationStoppedTime"

        if [ $JAVA_VER_MINOR -ge 8 ]; then
                JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedClassPointers"
                JAVA_OPTS="$JAVA_OPTS -XX:CompressedClassSpaceSize=1024M"
                JAVA_OPTS="$JAVA_OPTS -XX:MetaspaceSize=512M"
                JAVA_OPTS="$JAVA_OPTS -XX:MaxMetaspaceSize=512M"
        elif [ $JAVA_VER_MINOR -le 7 ]; then
                JAVA_OPTS="$JAVA_OPTS -XX:PermSize=256M"
                JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=256M"
                JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"
        fi
fi

### Linux Large Page Setting
if [ $USE_LARGEPAGE == "true" ]; then
	JAVA_OPTS="$JAVA_OPTS -XX:+UseLargePages";
fi

JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.resolver.warning=true"

### byteman
JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=org.jboss.byteman"

##################################################
# Bind Address
##################################################
JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address=$BIND_ADDR"
JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address.management=$MGNT_ADDR"
JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address.private=$PRIVATE_ADDR"
JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address.unsecure=$UNSECURE_ADDR"

JAVA_OPTS="$JAVA_OPTS -Djboss.default.multicast.address=$MULTICAST_ADDR"
JAVA_OPTS="$JAVA_OPTS -Djboss.messaging.cluster.password=$CLUSTER_PASSWD"
JAVA_OPTS="$JAVA_OPTS -Djboss.messaging.group.address=$MESSAGE_ADDR"
JAVA_OPTS="$JAVA_OPTS -Djboss.messaging.group.port=$MESSAGE_PORT"

# Management
JAVA_OPTS="$JAVA_OPTS -Djboss.management.http.port=$MGNT_HTTP_PORT"
JAVA_OPTS="$JAVA_OPTS -Djboss.management.https.port=$MGNT_HTTPS_PORT"

# Port Offset
JAVA_OPTS="$JAVA_OPTS -Djboss.socket.binding.port-offset=$PORT_OFFSET"

# Ports
JAVA_OPTS="$JAVA_OPTS -Djboss.ajp.port=$PORT_AJP"
JAVA_OPTS="$JAVA_OPTS -Djboss.http.port=$PORT_HTTP"
JAVA_OPTS="$JAVA_OPTS -Djboss.https.port=$PORT_HTTPS"

# modcluster proxy list
#JAVA_OPTS="$JAVA_OPTS -Djboss.mod_cluster.proxyList=address1:port1,address2:port2"
#JAVA_OPTS="$JAVA_OPTS -Djboss.mod_cluster.excludedContexts=host1:context1,host2:context2,host3:context3"
#JAVA_OPTS="$JAVA_OPTS -Djboss.mod_cluster.jvmRoute="

### JBoss Env Setting - Global
#JAVA_OPTS="$JAVA_OPTS -Djboss.qualified.host.name=$NODE_NAME"
JAVA_OPTS="$JAVA_OPTS -Djboss.home.dir=$JBOSS_HOME"
JAVA_OPTS="$JAVA_OPTS -Djboss.host.name=$NODE_NAME"
JAVA_OPTS="$JAVA_OPTS -Djboss.host.default.config=$HOST_CONFIG_FILE"
JAVA_OPTS="$JAVA_OPTS -Djboss.node.name=$NODE_NAME"
JAVA_OPTS="$JAVA_OPTS -DjvmRoute=$NODE_NAME"
JAVA_OPTS="$JAVA_OPTS -Djboss.tx.node.id=$NODE_NAME"
JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.boot.log.file=$LOG_HOME/boot.log"

### JBoss Env Setting - Standalone mode
JAVA_OPTS="$JAVA_OPTS -Djboss.server.base.dir=$SERVER_BASE_DIR"
JAVA_OPTS="$JAVA_OPTS -Djboss.server.default.config=$SERVER_CONFIG_FILE"
JAVA_OPTS="$JAVA_OPTS -Djboss.server.log.dir=$LOG_HOME"

JAVA_OPTS="$JAVA_OPTS -Djava.library.path=$LD_LIBRARY_PATH"

### Custom Settings
#JAVA_OPTS="$JAVA_OPTS -Dlogging.configuration=file:CONF_DIR/logging.properties"

export JAVA_OPTS

echo "================================================"
echo "JBOSS_HOME=$JBOSS_HOME"
echo "SERVER_HOME=$SERVER_HOME"
echo "NODE_NAME=$NODE_NAME"
echo "HOST_ADDR=$HOST_ADDR"
echo "SERVER_CONFIG_FILE=$SERVER_CONFIG_FILE"
echo "JAVA_VER=$JAVA_VER"
echo "JAVA_OPTS=$JAVA_OPTS"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
echo "================================================"
# EOF
jboss.properties
org.apache.catalina.connector.URI_ENCODING=UTF-8
org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING=true

org.apache.catalina.connector.URI_ENCODING=UTF-8
org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING=true
org.hornetq.core.message.impl.HDR_DUPLICATE_DETECTION_ID=$NODE_NAME
# Cluster Property
jvmRoute=$NODE_NAME
jboss-cli.sh

#!/bin/sh
ABSOLUTE_PATH="$(cd $(dirname "$0") && pwd -P)"
PROFILE_PATH="${ABSOLUTE_PATH%/*}"
DIR_NAME="${PROFILE_PATH##*/}"	# bin dir
#DIR_NAME="${ABSOLUTE_PATH##*/}"	# root dir

. $ABSOLUTE_PATH/jboss.env

#export JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=false "

if [ "$MGNT_ADDR" == "0.0.0.0" ]
then
	MGNT_ADDR=127.0.0.1
fi

echo "$JBOSS_HOME/bin/jboss-cli.sh  --controller=$MGNT_ADDR:$((MGNT_HTTP_PORT + PORT_OFFSET)) --connect $@"
$JBOSS_HOME/bin/jboss-cli.sh  --controller=$MGNT_ADDR:$((MGNT_HTTP_PORT + PORT_OFFSET)) --connect $@
jstat.sh
#!/bin/sh
ABSOLUTE_PATH="$(cd $(dirname "$0") && pwd -P)"
PROFILE_PATH="${ABSOLUTE_PATH%/*}"
DIR_NAME="${PROFILE_PATH##*/}"	# bin dir
#DIR_NAME="${ABSOLUTE_PATH##*/}"	# root dir

. $ABSOLUTE_PATH/jboss.env
INTERVAL=${1:-1}

PID=`ps -ef | grep java | grep "NODE_NAME=$NODE_NAME" | grep "jboss.server.base.dir=$SERVER_BASE_DIR" | awk '{print $2}'`
echo "PID:$PID"

if [ "$PID" == "" ]
then
    echo "$NODE_NAME is not running";
    exit 1;
fi

echo "jstat -gc $PID $((INTERVAL*1000))"
jstat -gc $PID $(($INTERVAL*1000))
# EOF
kill.sh
#!/bin/sh
ABSOLUTE_PATH="$(cd $(dirname "$0") && pwd -P)"
PROFILE_PATH="${ABSOLUTE_PATH%/*}"
DIR_NAME="${PROFILE_PATH##*/}"	# bin dir
#DIR_NAME="${ABSOLUTE_PATH##*/}"	# root dir

. $ABSOLUTE_PATH/jboss.env

PID=`ps -ef | grep java | grep "NODE_NAME=$NODE_NAME" | grep "jboss.server.base.dir=$SERVER_BASE_DIR" | awk '{print $2}'`
echo $PID

if [ "$PID" == "" ]
then
    echo "JBoss SERVER - [$NODE_NAME] is NOT RUNNING..."
    exit 1;
fi
#ps -ef | grep java | grep "NODE_NAME=$NODE_NAME" | grep "jboss.server.base.dir=$SERVER_BASE_DIR" | awk {'print "kill -9 " $2'} | sh -x
kill -9 $PID

echo "Killing down SERVER $NODE_NAME..."
sleep 10
multicast_receive.sh
#!/bin/sh
ABSOLUTE_PATH="$(cd $(dirname "$0") && pwd -P)"
PROFILE_PATH="${ABSOLUTE_PATH%/*}"
DIR_NAME="${PROFILE_PATH##*/}"	# bin dir
#DIR_NAME="${ABSOLUTE_PATH##*/}"	# root dir

. $ABSOLUTE_PATH/jboss.env

java -cp $JBOSS_HOME/bin/client/jboss-client.jar org.jgroups.tests.McastReceiverTest -mcast_addr $MULTICAST_ADDR -port 5555
# EOF
shutdown.sh
#!/bin/sh
ABSOLUTE_PATH="$(cd $(dirname "$0") && pwd -P)"
PROFILE_PATH="${ABSOLUTE_PATH%/*}"
DIR_NAME="${PROFILE_PATH##*/}"  # bin dir
#DIR_NAME="${ABSOLUTE_PATH##*/}"        # root dir

. $ABSOLUTE_PATH/jboss.env

PID=`ps -ef | grep java | grep "NODE_NAME=$NODE_NAME " | awk '{print $2}'`
echo "PID:$PID"

if [ "$PID" == "" ]
then
    echo "JBoss SERVER - [$NODE_NAME] is NOT RUNNING..."
    exit 1;
fi
if [ "$PORT_OFFSET" != "" ]
then
	MGNT_HTTP_PORT=$(( $MGNT_HTTP_PORT + $PORT_OFFSET ))
fi

if [ "$MGNT_ADDR" == "0.0.0.0" ]
then
	MGNT_ADDR="127.0.0.1"
fi

echo "$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$MGNT_ADDR:$MGNT_HTTP_PORT --command=shutdown"
$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$MGNT_ADDR:$MGNT_HTTP_PORT --command=shutdown

if [ $? != 0 ]
then
        exit 1
fi
echo "Server $NODE_NAME Shutting Down..."
while true
do
PID=`ps -ef | grep java | grep "NODE_NAME=$NODE_NAME " | awk '{print $2}'`
echo "PID:$PID"

        if [ "$PID" == "" ]
        then
		echo "Shutdown complete"
                break
        fi
        sleep 2
done
echo "Done."
shutdown_pw.sh

#!/bin/sh

ABSOLUTE_PATH="$(cd $(dirname "$0") && pwd -P)"
PROFILE_PATH="${ABSOLUTE_PATH%/*}"
DIR_NAME="${PROFILE_PATH##*/}"  # bin dir
#DIR_NAME="${ABSOLUTE_PATH##*/}"        # root dir

. $ABSOLUTE_PATH/jboss.env

PID=`ps -ef | grep java | grep "NODE_NAME=$NODE_NAME " | awk '{print $2}'`
echo $PID

if [ "$PID" == "" ]
then
    echo "JBoss SERVER - [$NODE_NAME] is NOT RUNNING..."
    exit 1;
fi
echo -n "Account:"
read USERNAME
echo -n "Password:"
read -s PASSWORD
echo ""

if [ "$PORT_OFFSET" != "" ]
then
	MGNT_HTTP_PORT=$(( $MGNT_HTTP_PORT + $PORT_OFFSET ))
fi

if [ "$MGNT_ADDR" == "0.0.0.0" ]
then
	MGNT_ADDR="127.0.0.1"
fi

echo "$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$MGNT_ADDR:$MGNT_HTTP_PORT --user=$USERNAME --password=$PASSWORD --command=shutdown"
$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$MGNT_ADDR:$MGNT_HTTP_PORT --user=$USERNAME --password=$PASSWORD --command=shutdown

if [ $? != 0 ]
then
        exit 1
fi
echo "Server $NODE_NAME Shutting Down..."
while true
do
PID=`ps -ef | grep java | grep "NODE_NAME=$NODE_NAME " | awk '{print $2}'`
echo "PID:$PID"

        if [ "$PID" == "" ]
        then
                break
        fi
        sleep 2
done
echo "Done."
start.sh
#!/bin/sh
ABSOLUTE_PATH="$(cd $(dirname "$0") && pwd -P)"
PROFILE_PATH="${ABSOLUTE_PATH%/*}"
DIR_NAME="${PROFILE_PATH##*/}"	# bin dir
#DIR_NAME="${ABSOLUTE_PATH##*/}"	# root dir

. $ABSOLUTE_PATH/jboss.env

PID=`ps -ef | grep java | grep "NODE_NAME=$NODE_NAME " | awk '{print $2}'`
echo $PID

if [ "$PID" != "" ]
then
    echo "JBoss SERVER - [$NODE_NAME] is already RUNNING..."
    exit 1;
fi
if [ -z "$NODE_NAME" ]
then
	echo -e "\e[33mWARNING\e[0m : \e[32mjboss.env is not configured.\e[0m"
	echo -e "\e[33mWARNING\e[0m : Program Exit."
	exit 1
fi
if [ "$DIR_NAME" != "$NODE_NAME" ]
then
	echo -e "\e[33mWARNING\e[0m : \e[32mDIRECTORY and NODE_NAME are not same\e[0m"
	echo -e "ABSOLUTE_PATH=$ABSOLUTE_PATH"
	echo -e "PROFILE_PATH=$PROFILE_PATH"
	echo -e "DIR_NAME=$DIR_NAME"
	echo -e "NODE_NAME=$NODE_NAME"
	echo -e "\e[33mWARNING\e[0m : Program Exit."
	exit 2
fi

if [ "$JBOSS_USER" != "$UNAME" ]
then
	echo -e "\e[33mWARNING\e[0m : Current User is [\e[31m$UNAME\e[0m]. MUST run to [\e[32m$JBOSS_USER\e[0m]."
	echo -e "\e[33mWARNING\e[0m : Program Exit."
	exit 3
fi

if [ ! -e "$JBOSS_HOME" -o ! -e "$SERVER_HOME" ]; then
	echo "JBOSS_HOME or SERVER_HOME is not Exists";
	exit 4
fi

if [ ! -d "$LOG_HOME" ]; then
	mkdir -p $LOG_HOME
fi

nohup $JBOSS_HOME/bin/standalone.sh -P=$SERVER_BIN_DIR/jboss.properties >> $LOG_HOME/jboss_console.log 2>&1 &

exit 0
# EOF
thread_dump.conf
#!/bin/sh
ABSOLUTE_PATH="$(cd $(dirname "$0") && pwd -P)"
PROFILE_PATH="${ABSOLUTE_PATH%/*}"
DIR_NAME="${PROFILE_PATH##*/}"	# bin dir
#DIR_NAME="${ABSOLUTE_PATH##*/}"	# root dir

. $ABSOLUTE_PATH/jboss.env

PID=`ps -ef | grep java | grep "NODE_NAME=$NODE_NAME" | grep "jboss.server.base.dir=$SERVER_BASE_DIR" | awk '{print $2}'`
echo "PID:$PID"

if [ "$PID" == "" ]
then
    echo "$NODE_NAME is not running";
    exit 1;
fi

for count in {1..5}
do
    echo "`date` Thread Dump : $count"

    echo "jstack -l $PID >> $PID-thread_dump-$DATE-$count.dmp"
    jstack -l $PID >> $PID-thread_dump-$DATE-$count.dmp

    echo "sleep 1 sec"
    sleep 1
done
sysctl.conf
# Allow a 25MB UDP receive buffer for JGroups
net.core.rmem_max = 26214400
# Allow a 1MB UDP send buffer for JGroups
net.core.wmem_max = 1048576
net.core.rmem_default = 26214400
net.core.wmem_default = 1048576

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *