Skip to content

Instantly share code, notes, and snippets.

@xandris
Created September 23, 2014 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xandris/be5e3b036a4a46073f13 to your computer and use it in GitHub Desktop.
Save xandris/be5e3b036a4a46073f13 to your computer and use it in GitHub Desktop.
JBoss management script
#!/bin/bash
JBOSS_HOME=$HOME/jboss
PATH="$PATH:$JBOSS_HOME/bin"
INIT_D_NAME="$(basename /etc/init.d/jboss*)"
cli() {
if [ "$#" -eq 0 ]; then
jboss-cli.sh -c
else
jboss-cli.sh -c "--command=$*"
fi
}
clean() {
local root="$JBOSS_HOME/standalone"
[ -d "$root" ] && rm -rf "$root/"{log,tmp}
}
cmd="$(basename "$0")"
if [ "$cmd" == "jboss" ]; then
cmd="$1"
shift
fi
case "$cmd" in
install)
dir="$(dirname "$0")"
base="$(basename "$0")"
cmds="start stop restart status reload clean logger log cli"
for cmd in $cmds; do
ln -s "$base" "$dir/$cmd"
done
;;
stop|start|restart|status)
sudo service "$INIT_D_NAME" "$cmd"
;;
redeploy)
name="$1"
cli "/deployment=$name:redeploy" \; "$@"
;;
reload)
cli :reload
;;
clean)
clean
;;
logger)
if [ "$#" -gt 1 ]; then
category="$1"
level="$2"
if [ "$level" == "remove" ]; then
cli /subsystem=logging/logger="$category":remove
else
cli <<EOF
/subsystem=logging/logger=$category:add
/subsystem=logging/logger=$category:write-attribute(name=level,value=$level)
EOF
fi
else
loggers="$(cli ls /subsystem=logging/logger=)"
levels="$(echo "$loggers"|while read logger; do
echo "/subsystem=logging/logger=$logger:read-attribute(name=level)"
done | cli | grep '"result" =>' | sed 's/.*"\([^"]*\)"$/\1/')"
paste -d= <(echo -n "$loggers") <(echo -n "$levels")
fi
;;
log)
less -Sn +F "$JBOSS_HOME/standalone/log/server.log"
;;
cli|*)
clicmd=()
if [ "$cmd" != "cli" ]; then
clicmd+=("$cmd")
fi
clicmd+=("$@")
cli "${clicmd[@]}"
esac
@xandris
Copy link
Author

xandris commented Sep 23, 2014

To use, just add it to a directory in your PATH. It would be helpful to have write permissions to that directory because you can say jboss install and it will create a handful of shortcuts to the various commands.

Commands:

  • jboss install: Install shortcuts for the below commands in the same directory this script lives.
  • jboss stop, jboss start, jboss status, jboss restart, stop, start, status, restart: Calls service <command> jboss-as-standalone (or therabouts)
  • jboss reload, reload': calls the CLI command:reload`.
  • jboss clean, clean: removes log and tmp directories. Run while stopped...
  • jboss logger [<logger name> (<level>|remove)], logger [<logger name> (<level>|remove)]: Lists all loggers and their levels, sets a logger's level, or removes a logger. Examples:
    • logger lists all loggers.
    • logger org.jboss DEBUG sets org.jboss to DEBUG.
    • logger org.jboss remove removes org.jboss. It now inherits from org and/or the root logger.
  • jboss log, log: view and start tailing the server log in less.
  • jboss cli [<command>], jboss <command>, cli [<command>]: with no <command>, launches the CLI. Otherwise, runs the given command. Examples:
    • jboss ls lists the stuff at the top of the management hierachy.
    • cli <<EOF starts piping a CLI script into the CLI.
  • jboss redeploy <deployment>, redeploy <deployment>: Redeploys the deployment with the given name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment