Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JBoss AS7+/Wildfly standalone start script
#!/bin/bash
#
# chkconfig: 2345 90 10
#
# JBoss Standalone Control Script
#
# Developped by:
# Sebastian Webber - sebastian@swebber.me
# Last update:
# 2013-08-01
#
## DEFAULT SETTINGS ###########################################
JBOSS_HOME="/usr/share/jbossas"
JBOSS_INSTANCE_NAME='prd-101'
JBOSS_INSTANCE_HOME="/var/lib/jbossas/server/${JBOSS_INSTANCE_NAME}"
JBOSS_INSTANCE_PARMS=''
JBOSS_INSTANCE_PARMS="${JBOSS_INSTANCE_PARMS} -c standalone-ha.xml" # CHANGE FOR DIFFERENT PROFILE
JBOSS_INSTANCE_PARMS="${JBOSS_INSTANCE_PARMS} -Djboss.node.name=$(hostname):${JBOSS_INSTANCE_NAME}"
JBOSS_INSTANCE_PARMS="${JBOSS_INSTANCE_PARMS} -Djboss.socket.binding.port-offset=100"
JBOSS_INSTANCE_PARMS="${JBOSS_INSTANCE_PARMS} -Djboss.bind.address.management=0.0.0.0"
JBOSS_INSTANCE_PARMS="${JBOSS_INSTANCE_PARMS} -Djboss.server.base.dir=${JBOSS_INSTANCE_HOME}"
SERVICE_USER="jboss"
## STOP EDITING HERE ###########################################
. /etc/init.d/functions
function do_stop() {
max_tries=30
killed=0
echo -n -e "Stopping '${JBOSS_INSTANCE_NAME}' instance."
while [ ${killed} -eq 0 ]; do
java_pid=$(ps u -C java | grep Standalone | grep "${JBOSS_INSTANCE_PARMS}" | awk '{print $2}')
if [ "${java_pid}X" != "X" ]; then
if [ "${max_tries}" -ne 0 ]; then
kill -15 ${java_pid}
max_tries=$((${max_tries} - 1))
else
kill -9 ${java_pid}
fi
sleep 1
echo -n -e "."
else
killed=1
fi
done
success ; echo "Instance was stopped... "
echo "remove pastas temporarias..."
/bin/rm -rf $JBOSS_INSTANCE_HOME/tmp/work/jboss.web/default-host/*
}
function get_currentpid() {
pid=$(ps u -C java | grep Standalone | grep "${JBOSS_INSTANCE_PARMS}" | awk '{print $2}')
echo $pid
}
function do_start() {
wait_for_stop
current_pid=$(get_currentpid)
if [ "${current_pid}X" = "X" ]; then
echo -n -e "Starting JBoss '${JBOSS_INSTANCE_NAME}' instance..."
_console_log="${JBOSS_INSTANCE_HOME}/log/console.log"
_cmd="${JBOSS_HOME}/bin/standalone.sh ${JBOSS_INSTANCE_PARMS} > ${_console_log} 2>&1 &"
su - ${SERVICE_USER} -c "${_cmd}"
if [ $? -eq 0 ]; then
sleep 3 && show_status
else
failure ; echo "Instance fail to start..."
fi
else
warning ; echo "Instance is already running in ${current_pid}."
exit 1
fi
}
function wait_for_stop() {
while [[ true ]]; do
current_pid=$( get_currentpid )
kill -15 ${current_pid}
if [ "${current_pid}X" != "X" ]; then
sleep 1
else
break
fi
done
}
function show_status() {
java_pid=$(get_currentpid)
if [ "${java_pid}X" != "X" ]; then
success ; echo "Instance is running in ${java_pid} process..."
else
warning ; echo "Instance is NOT running..."
exit 1
fi
}
function show_usage() {
this_script=$(basename ${0})
echo "Usage: ${this_script} (start|stop|restart|status|help)"
}
case "${1}" in
start) do_start ;;
stop) do_stop;;
restart) do_stop ; do_start ;;
status) show_status ;;
*) show_usage ;;
esac
exit $?
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.