Skip to content

Instantly share code, notes, and snippets.

@willvanwazer

willvanwazer/jboss

Forked from lionelg3/jboss-as
Last active Dec 13, 2015
Embed
What would you like to do?
#!/bin/sh
# Load JBoss AS init.d configuration.
if [ -z "$JBOSS_CONF" ]; then
JBOSS_CONF="/etc/jboss/jboss.conf"
fi
[ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"
if [ -z "$JBOSS_HOME" ]; then
JBOSS_HOME=/opt/jboss
fi
export JBOSS_HOME
if [ -z "JBOSS_MODE" ]; then
JBOSS_MODE=standalone
fi
if [ -z "$JBOSS_PIDFILE" ]; then
JBOSS_PIDFILE=/var/run/jboss/jboss-standalone.pid
fi
export JBOSS_PIDFILE
if [ -z "$JBOSS_CONSOLE_LOG" ]; then
JBOSS_CONSOLE_LOG=/var/log/jboss/console.log
fi
if [ -z "$STARTUP_WAIT" ]; then
STARTUP_WAIT=30
fi
if [ -z "$SHUTDOWN_WAIT" ]; then
SHUTDOWN_WAIT=30
fi
if [ -z "$JBOSS_CONFIG" ]; then
JBOSS_CONFIG=standalone.xml
fi
if [ -z "$JBOSS_USER" ]; then
JBOSS_USER=jboss
fi
if [ -z "$JBOSS_HOST" ]; then
JBOSS_HOST=127.0.0.1
fi
JBOSS_SCRIPT=$JBOSS_HOME/bin/$JBOSS_MODE.sh
prog='jboss'
CMD_PREFIX=''
start() {
echo -n "Starting $prog: "
if [ -f $JBOSS_PIDFILE ]; then
read ppid < $JBOSS_PIDFILE
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo -n "$prog is already running"
echo "Failure"
echo
return 1
else
rm -f $JBOSS_PIDFILE
fi
fi
mkdir -p $(dirname $JBOSS_CONSOLE_LOG)
cat /dev/null > $JBOSS_CONSOLE_LOG
mkdir -p $(dirname $JBOSS_PIDFILE)
echo "chown $JBOSS_USER $(dirname $JBOSS_PIDFILE)"
chown $JBOSS_USER $(dirname $JBOSS_PIDFILE) || true
#$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT 2>&1 > $JBOSS_CONSOLE_LOG &
#$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT &
if [ ! -z "$JBOSS_USER" ]; then
su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG -b $JBOSS_HOST" 2>&1 > $JBOSS_CONSOLE_LOG &
fi
count=0
launched=false
until [ $count -gt $STARTUP_WAIT ]
do
grep 'JBoss .*started in' $JBOSS_CONSOLE_LOG > /dev/null
if [ $? -eq 0 ] ; then
launched=true
break
fi
sleep 1
let count=$count+1;
done
echo "Success"
echo
return 0
}
stop() {
echo -n $"Stopping $prog: "
count=0;
if [ -f $JBOSS_PIDFILE ]; then
read kpid < $JBOSS_PIDFILE
let kwait=$SHUTDOWN_WAIT
# Try issuing SIGTERM
kill -15 $kpid
until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
do
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
kill -9 $kpid
fi
fi
rm -f $JBOSS_PIDFILE
echo "Success"
echo
}
case "$1" in
start)
echo "Starting JBoss AS7..."
start
;;
stop)
echo "Stopping JBoss AS7..."
stop
;;
log)
echo "Showing server.log..."
tail -1000f ${JBOSS_HOME}/standalone/log/server.log
;;
console)
echo "Showing console.log..."
tail -1000f ${JBOSS_CONSOLE_LOG}
;;
*)
echo "Usage: /etc/init.d/jboss {start|stop|log|console}"
exit 1
;; esac
exit 0
# General configuration for the JBoss AS 7 init.d scripts
# The username who should own the process.
#
JBOSS_USER=jboss
# The app server path
# ls - /opt/jboss-as-7.1.1.Final /opt/jboss-as
JBOSS_HOME=/opt/jboss
# The amount of time to wait for startup
#
# STARTUP_WAIT=30
# The amount of time to wait for shutdown
#
# SHUTDOWN_WAIT=30
# Location to keep the console log
#
# JBOSS_CONSOLE_LOG=/var/log/jboss/console.log
# Running script
#JBOSS_SCRIPT=$JBOSS_HOME/bin/domain.sh
#JBOSS_SCRIPT=$JBOSS_HOME/bin/standalone.sh
# Running mode (standalone or domain)
JBOSS_MODE=standalone
# Running "standalone" configuration
#JBOSS_CONFIG=standalone-ha.xml
#JBOSS_CONFIG=standalone-full.xml
JBOSS_CONFIG=standalone.xml
# Running "domain" configuration
#JBOSS_CONFIG=domain.xml
#JBOSS_CONFIG=host-master.xml
#JBOSS_CONFIG=host-slave.xml
# IP Address to bind JBoss to:
#JBOSS_HOST=0.0.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment