Created
September 23, 2014 22:30
-
-
Save xandris/be5e3b036a4a46073f13 to your computer and use it in GitHub Desktop.
JBoss management script
This file contains hidden or 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 | |
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 sayjboss installand 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: Callsservice <command> jboss-as-standalone(or therabouts)jboss reload,reload': calls the CLI command:reload`.jboss clean,clean: removeslogandtmpdirectories. 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:loggerlists all loggers.logger org.jboss DEBUGsetsorg.jbosstoDEBUG.logger org.jboss removeremovesorg.jboss. It now inherits fromorgand/or the root logger.jboss log,log: view and start tailing the server log inless.jboss cli [<command>],jboss <command>,cli [<command>]: with no<command>, launches the CLI. Otherwise, runs the given command. Examples:jboss lslists the stuff at the top of the management hierachy.cli <<EOFstarts piping a CLI script into the CLI.jboss redeploy <deployment>,redeploy <deployment>: Redeploys the deployment with the given name.