#!/bin/sh
#
# Resin startup script.
#
# Borrowed from jakarta-tomcat41
#
# $FreeBSD: ports/www/resin2/files/resin.sh.in,v 1.2 2004/07/02 22:10:15 glewis Exp $
#

# Determine PREFIX
if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/${0##*/}\$"); then
    echo "$0: Cannot determine the PREFIX" >&2
    exit 1
fi

# Set some variables
MYSELF=`basename $0`
ARGS="-conf $PREFIX/etc/resin2.xml \
-chdir \
-name resin2 \
-class com.caucho.server.http.HttpServer \
-pid /var/run/resin2.pid"
PATH=/usr/sbin:/usr/bin:/bin

unset CLASSPATH
export JAVA_HOME=/usr/local/jdk1.4.2
export RESIN_HOME=$PREFIX/resin2

set -e

case "$1" in
    start)
        echo -n ' '
        truncate -s 0 /var/run/resin2.pid
        chown www:wheel /var/run/resin2.pid
        chmod 600 /var/run/resin2.pid
        su -f -m www -c "exec $PREFIX/sbin/resin2ctl $ARGS start" \
            >/dev/null && echo -n 'resin2'
        ;;

    stop)
        echo -n ' '
        chown www:wheel /var/run/resin2.pid
        chmod 600 /var/run/resin2.pid
        su -f -m www -c "exec $PREFIX/sbin/resin2ctl $ARGS stop" \
            >/dev/null 2>&1 ; echo -n 'resin2'
        ;;
    *)
        echo ""
        echo "Usage: ${MYSELF} { start | stop }"
        echo ""
        exit 64
        ;;
esac
