ports/java/jboss5/files/jboss5.sh.in
Doug Barton 1d6b4b3f91 Begin the process of deprecating sysutils/rc_subr by
s#. %%RC_SUBR%%#. /etc/rc.subr#
2010-03-27 00:15:24 +00:00

113 lines
2.9 KiB
Bash

#!/bin/sh
#
# %%APP_SHORTNAME%% startup script.
#
# $FreeBSD$
#
# PROVIDE: %%APP_SHORTNAME%%
# REQUIRE: NETWORKING SERVERS
# Add the following lines to /etc/rc.conf to enable %%APP_SHORTNAME%%:
# %%APP_SHORTNAME%%_enable (bool): Set to "YES" to enable %%APP_SHORTNAME%%
# %%APP_SHORTNAME%%_jvm_opts (str): Extra JVM flags.
# %%APP_SHORTNAME%%_args (str): Optional arguments to JBoss
# %%APP_SHORTNAME%%_logging (str) JBoss log output. A pipe command may be used.
#
. /etc/rc.subr
%%APP_SHORTNAME%%_user="%%USER%%"
%%APP_SHORTNAME%%_logdir="%%LOG_DIR%%"
name="%%APP_SHORTNAME%%"
rcvar=`set_rcvar`
load_rc_config $name
%%APP_SHORTNAME%%_enable="${%%APP_SHORTNAME%%_enable:-"NO"}"
%%APP_SHORTNAME%%_jvm_opts="${%%APP_SHORTNAME%%_jvm_opts:-"-server -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"}"
%%APP_SHORTNAME%%_logging="${%%APP_SHORTNAME%%_logging:-">> ${%%APP_SHORTNAME%%_logdir}/stdout.log 2>> ${%%APP_SHORTNAME%%_logdir}/stderr.log"}"
start_cmd="%%APP_SHORTNAME%%_start"
stop_cmd="%%APP_SHORTNAME%%_stop"
pidfile="%%PID_FILE%%"
JBOSS_HOME="%%APP_HOME%%"
JBOSS_DEPLOY="%%DEPLOY_DIR%%"
JBOSS_MAIN="org.jboss.Main"
JAVA_OPTS="${%%APP_SHORTNAME%%_jvm_opts} \
-Djboss.server.base.dir=${JBOSS_DEPLOY} \
-Djboss.server.base.url=file://${JBOSS_DEPLOY} \
-Djava.endorsed.dirs=${JBOSS_HOME}/lib/endorsed \
-classpath ${JBOSS_HOME}/bin/run.jar ${JBOSS_MAIN}"
%%APP_SHORTNAME%%_start ()
{
if [ ! -d "${%%APP_SHORTNAME%%_logdir}" ]
then
mkdir -p ${%%APP_SHORTNAME%%_logdir}
chown ${%%APP_SHORTNAME%%_user} ${%%APP_SHORTNAME%%_logdir}
fi
echo "Starting %%APP_SHORTNAME%%."
daemon -u ${%%APP_SHORTNAME%%_user} sh -c "java ${JAVA_OPTS} ${%%APP_SHORTNAME%%_args} ${%%APP_SHORTNAME%%_logging} &"
sleep 1 # let daemon(8) and sh(1) finish before executing pgrep(1)
pgrep -U ${%%APP_SHORTNAME%%_user} -f ${JBOSS_MAIN} > ${pidfile}
chown ${%%APP_SHORTNAME%%_user} $pidfile
}
%%APP_SHORTNAME%%_stop ()
{
# Subvert the check_pid_file procname check.
if [ -f ${pidfile} ]
then
read rc_pid junk < $pidfile
if [ ! -z "${rc_pid}" ]
then
procname=`ps -o ucomm= ${rc_pid}`
fi
fi
rc_pid=$(check_pidfile $pidfile *$procname*)
if [ -z "${rc_pid}" ]
then
[ -n "${rc_fast}" ] && return 0
if [ -n "${pidfile}" ]
then
echo "${name} not running? (check ${pidfile})."
else
echo "${name} not running?"
fi
return 1
fi
echo "Stopping ${name}."
kill ${rc_pid} 2> /dev/null
jboss_wait_max_for_pid %%STOP_TIMEOUT%% ${rc_pid}
kill -KILL ${rc_pid} 2> /dev/null && echo "Killed."
rm -f ${pidfile}
}
jboss_wait_max_for_pid ()
{
_timeout=$1
shift
_pid=$1
_prefix=
while [ $_timeout -gt 0 ]
do
echo -n ${_prefix:-"Waiting (max $_timeout secs) for PIDS: "}$_pid
_prefix=", "
sleep 2
kill -0 $_pid 2> /dev/null || break
_timeout=$(($_timeout-2))
done
if [ -n "$_prefix" ]; then
echo "."
fi
}
run_rc_command "$1"