Skip to content

Instantly share code, notes, and snippets.

@amusarra
Created February 22, 2012 22:32
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 amusarra/1888006 to your computer and use it in GitHub Desktop.
Save amusarra/1888006 to your computer and use it in GitHub Desktop.
Liferay Portal JBoss Init Script
#!/bin/sh
#
# $Id: jboss_init_redhat.sh 81068 2008-11-14 15:14:35Z dimitris@jboss.org $
#
# JBoss Control Script
#
# To use this script run it as root - it will switch to the specified user
#
# Here is a little (and extremely primitive) startup/shutdown script
# for RedHat systems. It assumes that JBoss lives in /usr/local/jboss,
# it's run by user 'jboss' and JDK binaries are in /usr/local/jdk/bin.
# All this can be changed in the script itself.
#
# Either modify this script for your requirements or just ensure that
# the following variables are set correctly before calling the script.
# Liferay Portal CE 6.0.x JBoss Bundle Init script for starting and stopping
#
# chkconfig: 35 80 30
# description: Liferay Portal startup script
# Source function library.
. /etc/rc.d/init.d/functions
# Setting Liferay Portal env
. /etc/profile.d/lportal.sh
#define where jboss is - this is the directory containing directories log, bin, conf etc
JBOSS_HOME=${JBOSS_HOME:-"/usr/local/jboss"}
#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
JBOSS_USER=${JBOSS_USER:-"jboss"}
#make sure java is in your path
JAVAPTH=${JAVA_BIN:-"/usr/local/jdk/bin"}
#configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"default"}
#if JBOSS_HOST specified, use -b to bind jboss services to that address
JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}
#define the classpath for the shutdown class
JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}
#define the script to use to start jboss
JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR"}
if [ "$JBOSS_USER" = "RUNASIS" ]; then
SUBIT=""
else
SUBIT="su - $JBOSS_USER -c "
fi
if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
# ensure the file exists
touch $JBOSS_CONSOLE
if [ ! -z "$SUBIT" ]; then
chown $JBOSS_USER $JBOSS_CONSOLE
fi
fi
if [ -e "$JBOSS_CONSOLE" ]; then
JBOSS_CONSOLE_BACKUP="${JBOSS_CONSOLE}.`date +%s`"
cp $JBOSS_CONSOLE $JBOSS_CONSOLE_BACKUP
chown $JBOSS_USER $JBOSS_CONSOLE_BACKUP
fi
if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
echo "WARNING: ignoring it and using /dev/null"
JBOSS_CONSOLE="/dev/null"
fi
#define what will be done with the console log
JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}
JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
# Via script Shutdown.sh
JBOSS_CMD_STOP="$JBOSS_HOME/bin/shutdown.sh -s $JBOSS_JNP_URL -S"
JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"}
if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
export PATH=$PATH:$JAVAPTH
fi
if [ ! -d "$JBOSS_HOME" ]; then
echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
exit 1
fi
case "$1" in
start)
echo -n $"Starting Liferay Portal:"
echo -n "$JBOSS_CMD_START:"
cd $JBOSS_HOME/bin
if [ -z "$SUBIT" ]; then
eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
else
$SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &"
fi
echo "OK"
;;
stop)
echo -n $"Stopping Liferay Portal:"
echo -n "$JBOSS_CMD_STOP:"
if [ -z "$SUBIT" ]; then
$JBOSS_CMD_STOP >${JBOSS_CONSOLE} 2>&1
else
$SUBIT "$JBOSS_CMD_STOP >${JBOSS_CONSOLE} 2>&1"
fi
echo "OK"
;;
restart)
$0 stop
$0 start
;;
*)
echo "usage: $0 (start|stop|restart|help)"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment