Last active
November 7, 2022 07:24
-
-
Save fkleon/7555983 to your computer and use it in GitHub Desktop.
A shell script to perform simple management operations on a JBoss instance.
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/sh | |
######################################################### | |
# A shell script to manage a JBoss instance. # | |
# # | |
# For a detailed description see wiki. # | |
# # | |
# Version: # | |
# 1.1.4 # | |
# Author(s): # | |
# - Frederik Leonhardt # | |
######################################################### | |
VERSION=1.1.4 | |
################# | |
# CONFIGURATION ######################################### | |
################# | |
JBOSS_PATH=/home/jboss/wildfly-8.1 # The path to the JBoss instance | |
PORT_OFFSET=0 | |
######################################################### | |
# calculate new management port | |
MGMT_PORT=`expr 9990 + $PORT_OFFSET` | |
# Starts the JBoss instance. | |
# Redirects console log to /dev/null to avoid spamming the shell. | |
start(){ | |
echo "Starting jboss..." | |
$JBOSS_PATH/bin/standalone.sh -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0.0 -Djboss.socket.binding.port-offset=$PORT_OFFSET> /dev/null 2>&1 & | |
} | |
# Gracefully stops JBoss instance via management CLI interface. | |
stop(){ | |
echo "Stopping jboss..." | |
sh $JBOSS_PATH/bin/jboss-cli.sh --connect controller=localhost:$MGMT_PORT command=:shutdown | |
if [ $? -ne 0 ] | |
then echo "Failed to gracefully stop JBoss." | |
fi | |
} | |
# Restarts JBoss. Experimental. | |
restart(){ | |
stop | |
if [ $? -ne 0 ] | |
then | |
echo "Killing Java processes..." | |
# protect against any services that can't stop before we restart | |
# (warning: this kills all Java instances running as current user) | |
killall java | |
fi | |
start | |
} | |
# Tails JBoss log to console. | |
log(){ | |
echo "Tailing jboss log..." | |
tail -f $JBOSS_PATH/standalone/log/server.log | |
} | |
# Cleans temp directories of JBoss. | |
clean(){ | |
echo "Cleaning JBoss directory..." | |
echo "Deleting data.." | |
rm -rf $JBOSS_PATH/standalone/data | |
echo "Deleting tmp.." | |
rm -rf $JBOSS_PATH/standalone/tmp | |
echo "Success, please start JBoss again." | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart | |
;; | |
log) | |
log | |
;; | |
clean) | |
stop | |
if [ $? -eq 0 ] | |
then clean | |
else echo "Failed to stop JBoss. Cancel clean." | |
fi | |
;; | |
*) | |
echo "JBoss Management Script" | |
echo "[version $VERSION]" | |
echo "[port offset $PORT_OFFSET]" | |
echo "" | |
echo "Usage: jboss {start|stop|restart|log|clean}" | |
exit 1 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update to support port offsets.