#!/bin/sh
#
# Resin startup script.
#
# Borrowed from jakarta-tomcat41
#
# $FreeBSD: ports/www/resin3/files/resin.sh.in,v 1.3 2004/06/24 07:43:27 vs 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/resin3/resin.xml \
-chdir \
-name resin3 \
-class com.caucho.server.resin.Resin \
-pid /var/run/resin3.pid"
PATH=/usr/sbin:/usr/bin:/bin

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

set -e

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

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