Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 63 additions & 35 deletions bin/init.d/jboss-custom.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/sh
#
# Rafael Liu <rafaelliu@gmail.com>
# Author: Rafael Liu <rafaelliu@gmail.com>
# Modified by: Anderson Deluiz <https://github.com/anddeluiz>
# Modified by: Karina Macedo <https://github.com/kmacedovarela>
# Modified by: Rodrigo Ramalho <https://github.com/hodrigohamalho>
#
# You really shouldn't be editing this. Most of variables defined here can be overwriten on jboss-init.sh:
# JBOSS_HOME: yes, you guessed it!
Expand All @@ -9,10 +12,14 @@
# JBOSS_STARTUP_WAIT: timout to consider a startup failed (process will be left intact)
# JBOSS_SHUTDOWN_WAIT: timout to consider a shutdown failed (process will be left intact)
# JBOSS_OPTS: custom JBoss options can go here
# JBOSS_DOMAIN_LOG_DIR: log directory for domain
# BIND_ADDRESS: general IP
# PUBLIC_ADDRESS: public IP (defaults to $BIND_ADDRESS)
# MANAGEMENT_ADDRESS: management IP (defaults to $BIND_ADDRESS)
# MANAGEMENT_PORT: management port (it's usefull to use more than one HC on same machine)
# MANAGEMENT_NATIVE_PORT: management native port (it's usefull to use more than one HC on same machine)
# MASTER_ADDRESS: address to which HC should connect
# MASTER_MGMT_PORT: master server management port (it's usefull to use more than one DC on same machine)
# JBOSS_DOMAIN_CONFIG: domain.xml to be used if it's a DC
# JBOSS_HOST_CONFIG: host.xml to be used (default: automatically detected)
# DOMAIN_PROFILE: path to the profile dir
Expand All @@ -31,7 +38,9 @@ fi
# Load Java configuration.
export JAVA_HOME

#
# Set defaults.
#

if [ -z "$JBOSS_HOME" ]; then
echo "ERROR: couldn't find JBOSS_HOME, must defined"
Expand All @@ -40,41 +49,40 @@ fi

export JBOSS_HOME

JBOSS_USER=${JBOSS_USER:-"jboss"}

JBOSS_CONSOLE_LOG=${JBOSS_CONSOLE_LOG:-"/dev/null"}

JBOSS_STARTUP_WAIT=${JBOSS_STARTUP_WAIT:-"30"}
JBOSS_SHUTDOWN_WAIT=${JBOSS_SHUTDOWN_WAIT:-"30"}

# initialize opts
JBOSS_OPTS=${JBOSS_OPTS:-""}

BIND_ADDRESS=${BIND_ADDRESS:-"127.0.0.1"}

PUBLIC_ADDRESS=${PUBLIC_ADDRESS:-"$BIND_ADDRESS"}

MANAGEMENT_ADDRESS=${MANAGEMENT_ADDRESS:-"$BIND_ADDRESS"}

DOMAIN_PROFILE=${DOMAIN_PROFILE:-"$JBOSS_HOME/domain"}

# check for a domain config file, defaults to domain.xml
JBOSS_CONSOLE_LOG=${JBOSS_CONSOLE_LOG:-"/dev/null"}
JBOSS_DOMAIN_CONFIG=${JBOSS_DOMAIN_CONFIG:-"domain.xml"}

JBOSS_DOMAIN_LOG_DIR=${JBOSS_DOMAIN_LOG_DIR:-"$PROFILE_HOME/log/"}
JBOSS_OPTS=${JBOSS_OPTS:-""}
JBOSS_SCRIPT=$JBOSS_HOME/bin/domain.sh
JBOSS_SHUTDOWN_WAIT=${JBOSS_SHUTDOWN_WAIT:-"30"}
JBOSS_STARTUP_WAIT=${JBOSS_STARTUP_WAIT:-"30"}
JBOSS_USER=${JBOSS_USER:-"jboss"}
MANAGEMENT_ADDRESS=${MANAGEMENT_ADDRESS:-"$BIND_ADDRESS"}
MANAGEMENT_NATIVE_PORT=${MANAGEMENT_NATIVE_PORT:-"9999"}
MANAGEMENT_PORT=${MANAGEMENT_PORT:-"9990"}
MASTER_MGMT_PORT=${MASTER_MGMT_PORT:-"9999"}
PUBLIC_ADDRESS=${PUBLIC_ADDRESS:-"$BIND_ADDRESS"}

#
# validations
#

if [ "$(id -un)" != "root" -a "$(id -un)" != "${JBOSS_USER}" ]
then
echo "ERROR: this must be run by user root or user ${JBOSS_USER}"
exit 1
fi

id $JBOSS_USER > /dev/null
if [ "$?" != "0" ]; then
echo "User '$JBOSS_USER' doesn't exist. Create it or change JBOSS_USER param"
echo "ERROR: User '$JBOSS_USER' doesn't exist. Create it or change JBOSS_USER param"
exit 1
fi

#
#
# Check if this is a DC and adjust config files and JBoss opts
#

if [ -z "$MASTER_ADDRESS" ]; then
Expand All @@ -85,8 +93,8 @@ else
# if there's no master, defaults to host-slave.xml (can still set explicitly)
JBOSS_HOST_CONFIG=${JBOSS_HOST_CONFIG:-"host-slave.xml"}

# also add master's address
JBOSS_OPTS="$JBOSS_OPTS --master-address=$MASTER_ADDRESS"
# also add master's address and port
JBOSS_OPTS="$JBOSS_OPTS --master-address=$MASTER_ADDRESS -Djboss.domain.master.port=${MASTER_MGMT_PORT}"
fi

# JBoss host's name (will be used in jboss-cli)
Expand All @@ -100,14 +108,34 @@ if [ ! "$HOST" ]; then
fi

# build final opts
JBOSS_OPTS="$JBOSS_OPTS -Djboss.domain.base.dir=$PROFILE_HOME --domain-config=$JBOSS_DOMAIN_CONFIG --host-config=$JBOSS_HOST_CONFIG -b $PUBLIC_ADDRESS -bmanagement $MANAGEMENT_ADDRESS"
JBOSS_OPTS="$JBOSS_OPTS -Djboss.domain.base.dir=$PROFILE_HOME --domain-config=$JBOSS_DOMAIN_CONFIG --host-config=$JBOSS_HOST_CONFIG -b $PUBLIC_ADDRESS -bmanagement $MANAGEMENT_ADDRESS -Djboss.domain.log.dir=$JBOSS_DOMAIN_LOG_DIR -Djboss.management.native.port=$MANAGEMENT_NATIVE_PORT -Djboss.management.http.port=$MANAGEMENT_PORT "

prog='jboss-as'

start() {
echo -n "Starting $prog: "
cat /dev/null > $JBOSS_CONSOLE_LOG
if [ -e $JBOSS_CONSOLE_LOG ]
then
if [ -w $JBOSS_CONSOLE_LOG ]
then
cat /dev/null > $JBOSS_CONSOLE_LOG
else
echo "ERROR: console log file $JBOSS_CONSOLE_LOG doesn't have write permission for user $JBOSS_USER"
exit 1
fi
else
if [ -w $(dirname ${JBOSS_CONSOLE_LOG}) ]
then
cat /dev/null > $JBOSS_CONSOLE_LOG
chmod 644 $JBOSS_CONSOLE_LOG
chown ${JBOSS_USER}:$(id -gn ${JBOSS_USER}) $JBOSS_CONSOLE_LOG
else
echo "ERROR: error creating console log file $JBOSS_CONSOLE_LOG"
echo "ERROR: check permissions for user $JBOSS_USER on $(dirname JBOSS_CONSOLE_LOG) directory."
exit 1
fi
fi

echo -n "Starting $prog: "
status &> /dev/null
if [ "$?" = "0" ]; then
echo "$prog already running"
Expand All @@ -127,7 +155,7 @@ start() {
if [ "$( id -un )" = "$JBOSS_USER" ]; then
$CMD 2>&1 > $JBOSS_CONSOLE_LOG &
elif [ "$( id -un )" = "root" ]; then
su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $CMD" 2>&1 > $JBOSS_CONSOLE_LOG &
su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 $CMD" 2>&1 > $JBOSS_CONSOLE_LOG &
else
failure
echo
Expand Down Expand Up @@ -282,7 +310,7 @@ dump_all() {
cli "/:read-resource(recursive=true,include-runtime=true)" &> "$DUMP_PATH/cli.dump" &

# copy logs
cp -a "$PROFILE_HOME/log" "$DUMP_PATH/log" &
cp -a "$JBOSS_DOMAIN_LOG_DIR" "$DUMP_PATH/log" &

# process controller
PC_PID=$( get_pids_for "Process Controller" )
Expand All @@ -307,7 +335,7 @@ dump_all() {
jmap -heap $PID &> "$DUMP_PATH/$SERVER/jmap.out"
fi

cp -a "$PROFILE_HOME/servers/$SERVER/log" "$DUMP_PATH/$SERVER/log" &
cp -a "$JBOSS_DOMAIN_LOG_DIR/servers/$SERVER/log" "$DUMP_PATH/$SERVER/log" &
done

tar zcvf "${DUMP_FILE}.tar.gz" "$DUMP_PATH" &> /dev/null
Expand All @@ -323,7 +351,7 @@ status() {

STATUS=$( cli "/host=$HOST:read-attribute(name=host-state)" 2> /dev/null | grep "result" | sed 's/.*=> "\(.*\)"/\1/g' )
if [ -z $STATUS ]; then
echo "$prog process is up, but CLI is not responsive (may be shuting down or botting)"
echo "$prog process is up, but CLI is not responsive (may be shuting down or booting)"
return 2
fi

Expand All @@ -332,7 +360,7 @@ status() {
}

cli() {
OPTS="--connect --controller=$MANAGEMENT_ADDRESS "
OPTS="--connect --controller=$MANAGEMENT_ADDRESS:$MANAGEMENT_NATIVE_PORT "
if [ ! -z "$*" ]; then
# hack: jboss-cli doesn't handle quotes well
FILE="/tmp/jboss-cli_$( date +%Y%m%d-%H%M%S%N )"
Expand All @@ -345,9 +373,9 @@ cli() {

tail_log() {
if [ $# = 0 ]; then
tail -100f "$PROFILE_HOME/log/host-controller.log"
tail -100f "$JBOSS_DOMAIN_LOG_DIR/host-controller.log"
else
tail -100f "$PROFILE_HOME/servers/$1/log/server.log"
tail -100f "$JBOSS_DOMAIN_LOG_DIR/servers/$1/server.log"
fi
}

Expand All @@ -362,8 +390,8 @@ case "$1" in
force_kill
;;
restart)
$0 stop
$0 start $2
stop
start $2
;;
status)
status
Expand Down
8 changes: 5 additions & 3 deletions domain/bin/jboss-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# description: JBoss AS Domain
# processname: domain
#
# Rafael Liu <rafaelliu@gmail.com>
# Author: Rafael Liu <rafaelliu@gmail.com>
# Modified by: Anderson Deluiz <https://github.com/anddeluiz>
#

derelativize() {
Expand All @@ -32,8 +33,9 @@ if [ -z "$JBOSS_HOME" ]; then
PROFILE_HOME=$( derelativize $DIR/../ )
JBOSS_HOME=$( derelativize $DIR/../../ )

if [ -z "$JBOSS_HOME/bin/product.conf" ]; then
echo "ERROR: couldn't auto-find JBOSS_HOME, must defined"
if [ ! -f "$JBOSS_HOME/bin/product.conf" ]; then
echo "ERROR: couldn't auto-find JBoss Application Server at ${JBOSS_HOME}"
echo "ERROR: Please check JBOSS_HOME environment variable."
exit 1
fi
fi
Expand Down
105 changes: 85 additions & 20 deletions domain/bin/setup.conf
Original file line number Diff line number Diff line change
@@ -1,21 +1,86 @@
#JBOSS_HOME=<auto discovered>
#JBOSS_DOMAIN_CONFIG=<auto discovered>
#JBOSS_HOST_CONFIG=<auto discovered>
#DOMAIN_PROFILE=<auto discovered>
#JAVA_HOME=<auto discovered>

#JBOSS_USER="jboss"
#JBOSS_STARTUP_WAIT=60
#JBOSS_SHUTDOWN_WAIT=60
#JBOSS_OPTS=""
#PUBLIC_ADDRESS="$BIND_ADDRESS"
#MANAGEMENT_ADDRESS="$BIND_ADDRESS"

BIND_ADDRESS="127.0.0.1"

# uncomment if (and only if) it's a remote HC
#MASTER_ADDRESS="xxx.xxx.xxx.xxx"

# need in order to use service jboss start console
JBOSS_CONSOLE_LOG="/tmp/jboss-$DOMAIN_PROFILE-console.log"
#
# Author: Rafael Liu <rafaelliu@gmail.com>
# Modified by: Anderson Deluiz <anderson.deluiz@gmail.com> - Jan 23rd, 2015
#
# This is the configuration file for jboss-init.sh and jboss-custom.sh scripts.
# jboss-init.sh script will load these variables to configure runtime environ-
# ment.
# A simple description of each configurable variable is provided. Further info
# can be obtained at: https://github.com/rafaelliu/jboss-scripts

# BIND_ADDRESS: general IP
# Default:
# BIND_ADDRESS=127.0.0.1

# JAVA_HOME: yes, you guess it!
# Default:
# JAVA_HOME=<auto discovered>

# JBOSS_CONSOLE_LOG: log file to which redirect ouput. Need in order to use service jboss start console
# Default:
# JBOSS_CONSOLE_LOG=/dev/null

# JBOSS_DOMAIN_CONFIG: domain.xml file to be used if it's a DC
# Default:
# JBOSS_DOMAIN_CONFIG=<auto discovered>

# JBOSS_DOMAIN_LOG_DIR: domain.xml file to be used if it's a DC
# Default:
# JBOSS_DOMAIN_LOG_DIR=$PROFILE_HOME/log

# JBOSS_HOME: yes, you guessed it again!
# Default:
# JBOSS_HOME=<auto discovered>

# JBOSS_HOST_CONFIG: host.xml file to be used
# Default:
# If MASTER_ADDRESS defined:
# JBOSS_HOST_CONFIG=host-slave.xml
# If MASTER_ADDRESS NOT defined:
# JBOSS_HOST_CONFIG=host-master.xml

# DOMAIN_PROFILE: path to the profile directory
# Default:
# DOMAIN_PROFILE=<auto discovered>

# JBOSS_USER: owner of the process
# Default:
# JBOSS_USER=jboss

# JBOSS_STARTUP_WAIT: timout to consider a startup failed (process will be left intact)
# Default:
# JBOSS_STARTUP_WAIT=30

# JBOSS_SHUTDOWN_WAIT: timout to consider a shutdown failed (process will be left intact)
# Default:
# JBOSS_SHUTDOWN_WAIT=30

# JBOSS_OPTS: custom JBoss options can go here
# Default:
# JBOSS_OPTS=""

# MANAGEMENT_ADDRESS: management IP (defaults to $BIND_ADDRESS)
# Default:
# MANAGEMENT_ADDRESS=$BIND_ADDRESS

# MANAGEMENT_NATIVE_PORT: management native port (it's usefull to use more than one HC on same machine)
# Default:
# MANAGEMENT_NATIVE_PORT=9999

# MANAGEMENT_PORT: HTTP management port (it's usefull to use more than one HC on same machine)
# Default:
# MANAGEMENT_PORT=9990

# MASTER_ADDRESS: FQDN or IP address to which HC should connect
# Default:
# MASTER_ADDRESS=<none>

# MASTER_MGMT_PORT: master server management port (it's usefull to use more than one DC on same machine)
# Only useful when MASTER_ADDRESS variable is set.
# Default:
# MASTER_MGMT_PORT=9999

# PUBLIC_ADDRESS: public IP (defaults to $BIND_ADDRESS)
# Default:
# PUBLIC_ADDRESS=$BIND_ADDRESS