Created
October 28, 2014 11:12
-
-
Save aldaris/caa6ef1e6cf140e5c6cb to your computer and use it in GitHub Desktop.
Making WildFly a little bit more usable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
WILDFLY_HOME=/Users/aldaris/wildfly-8.1.0.Final | |
CONNECT_EXCEPTION=ConnectException | |
RUNNING=running | |
function usage { | |
echo "Usage: jbossadmin start|stop|restart [<counter>]" | |
echo "If <counter> is absent, 1 is assumed" | |
exit -1 | |
} | |
if [ $# -eq 0 ] ; then | |
usage | |
fi | |
function get_state { | |
state=`${WILDFLY_HOME}/bin/jboss-cli.sh --controller=127.0.0.1:${ADMIN_PORT} --connect 'read-attribute server-state' 2>&1` | |
if [[ $state == *${CONNECT_EXCEPTION}* ]]; then | |
echo ${CONNECT_EXCEPTION} | |
else | |
echo $state | |
fi | |
} | |
function start { | |
if [ $(get_state) != ${CONNECT_EXCEPTION} ] ; then | |
echo "Node $1 is already running" | |
else | |
${WILDFLY_HOME}/bin/standalone.sh -Djboss.server.base.dir=${WILDFLY_HOME}/standalone-$1 --debug ${DEBUG_PORT} > /dev/null & | |
wait_until "${RUNNING}" | |
fi | |
} | |
function stop { | |
if [ $(get_state) = ${CONNECT_EXCEPTION} ] ; then | |
echo "Node $1 is not running" | |
else | |
${WILDFLY_HOME}/bin/jboss-cli.sh --controller=127.0.0.1:${ADMIN_PORT} --connect ":shutdown" 2> /dev/null | |
wait_until "${CONNECT_EXCEPTION}" | |
fi | |
} | |
function restart { | |
if [ $(get_state) = ${CONNECT_EXCEPTION} ] ; then | |
echo "Node $1 is not running, starting up instead" | |
start $1 | |
else | |
${WILDFLY_HOME}/bin/jboss-cli.sh --controller=127.0.0.1:${ADMIN_PORT} --connect ":shutdown(restart=true)" 2> /dev/null | |
wait_until "${RUNNING}" | |
fi | |
} | |
function wait_until { | |
while true | |
do | |
state=$(get_state) | |
if [[ $state == $1 ]] ; then | |
break | |
else | |
echo $state | |
sleep 2 | |
fi | |
done | |
} | |
if [ $# -eq 1 ] ; then | |
NODES=1 | |
else | |
NODES=$2 | |
fi | |
for (( i = 0; i < ${#NODES}; i++ )) | |
do | |
node=${NODES:$i:1} | |
DEBUG_PORT=$((($node - 1) * 10000 + 9009)) | |
ADMIN_PORT=$((($node - 1) * 10000 + 9990)) | |
case $1 in | |
start) | |
start $node | |
;; | |
stop) | |
stop $node | |
;; | |
restart) | |
restart $node | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment