#!/bin/bash ### BEGIN INIT INFO # Provides: jboss # Required-Start: postgresql # Required-Stop: postgresql # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: JBoss 5.1 AS ### END INIT INFO JAVA_HOME=$JAVA_HOME JBOSS_HOME=/usr/local/jboss JBOSS_SERVER=gazelle JBOSS_BIND=0.0.0.0 #JBOSS_PORTS=ports-01 JBOSS_PORTS=ports-default JBOSS_USER=jboss JBOSS_CONSOLE=/var/log/jboss/${JBOSS_SERVER}.log # Increase max memory with Xmx #JAVA_OPTS="-server -Xms1024m -XX:MaxPermSize=1024m -Xmx2048m" # use better garbage collector : G1 #JAVA_OPTS="$JAVA_OPTS -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:+DisableExplicitGC" # next line may improve garbage collector #JAVA_OPTS="$JAVA_OPTS -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=32 -XX:+UseTLAB -XX:TLABSize=256k" # Optionnal garbage collector logs # JAVA_OPTS="$JAVA_OPTS -verbose:gc -Xloggc:/var/log/jboss/gc.log" # debug server #JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n" start(){ # if garbage collector logs # cp /var/log/jboss/gc.log /var/log/jboss/gc-`date +"%Y-%m-%d-%H-%M-%S"`.log su ${JBOSS_USER} -s /bin/sh -c "rm -rf ${JBOSS_HOME}/server/${JBOSS_SERVER}/tmp" su ${JBOSS_USER} -s /bin/sh -c "mkdir ${JBOSS_HOME}/server/${JBOSS_SERVER}/tmp" # su ${JBOSS_USER} -s /bin/sh -c "rm -rf ${JBOSS_HOME}/server/${JBOSS_SERVER}/log/*" su ${JBOSS_USER} -s /bin/sh -c "rm -rf ${JBOSS_HOME}/server/${JBOSS_SERVER}/work/*" su ${JBOSS_USER} -s /bin/sh -c "rm -rf ${JBOSS_HOME}/server/${JBOSS_SERVER}/data/wsdl/*" CMD="export JAVA_HOME=${JAVA_HOME};export JAVA_OPTS=\"${JAVA_OPTS}\";cd ${JBOSS_HOME};${JBOSS_HOME}/bin/run.sh -c ${JBOSS_SERVER} -b ${JBOSS_BIND} -Djboss.service.binding.set=${JBOSS_PORTS}" echo Starting JBoss with: $CMD echo Running Jboss as user "${JBOSS_USER}" - log in ${JBOSS_CONSOLE} env - su -l ${JBOSS_USER} -s /bin/sh -c "${CMD} > ${JBOSS_CONSOLE} 2>&1 &" } stop(){ export JBOSS_PID=`ps -efl | grep "${JAVA_HOME}" | grep "\-c ${JBOSS_SERVER}" | grep "${JBOSS_BIND}" | awk '{print $4}'` # If a JBoss server is running, we stop it if [ $JBOSS_PID ] then echo "Stopping JBoss AS (${JBOSS_SERVER} for user ${JBOSS_USER})... (kill -9 ${JBOSS_PID})" su ${JBOSS_USER} -s /bin/sh -c "kill -9 ${JBOSS_PID}" else echo "JBoss AS ($JBOSS_SERVER for user $JBOSS_USER) is not started" fi } restart(){ stop sleep 2 start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo "Usage: local-jboss {start|stop|restart}" exit 1 esac exit 0