Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
General configuration for the JBoss AS 7.1.1-Final init.d scripts for Debian (/etc/jboss-as/jboss-as.conf and /etc/init.d/jboss-as)
#!/bin/sh
# Load JBoss AS init.d configuration.
if [ -z "$JBOSS_CONF" ]; then
JBOSS_CONF="/etc/jboss-as/jboss-as.conf"
fi
[ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"
if [ -z "$JBOSS_HOME" ]; then
JBOSS_HOME=/opt/jboss-as
fi
export JBOSS_HOME
if [ -z "JBOSS_MODE" ]; then
JBOSS_MODE=standalone
fi
if [ -z "$JBOSS_PIDFILE" ]; then
JBOSS_PIDFILE=/var/run/jboss-as/jboss-as-standalone.pid
fi
export JBOSS_PIDFILE
if [ -z "$JBOSS_CONSOLE_LOG" ]; then
JBOSS_CONSOLE_LOG=/var/log/jboss-as/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-as
fi
JBOSS_SCRIPT=$JBOSS_HOME/bin/$JBOSS_MODE.sh
prog='jboss-as'
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" 2>&1 > $JBOSS_CONSOLE_LOG &
fi
count=0
launched=false
until [ $count -gt $STARTUP_WAIT ]
do
grep 'JBoss AS.*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-as {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-as
# The app server path
# ls - /opt/jboss-as-7.1.1.Final /opt/jboss-as
JBOSS_HOME=/opt/jboss-as
# 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-as/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
@alfredocambera

This comment has been minimized.

Copy link

@alfredocambera alfredocambera commented Jun 19, 2013

Really useful. It helped me a lot. thaks

@korEn3tz

This comment has been minimized.

Copy link

@korEn3tz korEn3tz commented Mar 18, 2017

Life saver, thank you for your scripts.

Made a few changes to get the job done for Ubuntu 14.04.5:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          jboss-as
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/Stop JBoss AS v7.1.1
### END INIT INFO
#
  1. Modified to run under #!/bin/bash otherwise when starting while the count was running out would show let unknown and not count thus not starting jboss
  2. Include the default run levels so sym links are done with: update-rc.d jboss-as defaults (assuming your script name is jboss-as)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.