#!/bin/sh
#
# $FreeBSD: ports/www/resin2/files/resin.sh.in,v 1.4 2006/12/16 02:14:26 rafan Exp $
#

# PROVIDE: resin2
# REQUIRE: LOGIN
# KEYWORD: shutdown

#
# Add the following line to /etc/rc.conf to enable resin2:
#
# resin2_enable="YES"
#

. /etc/rc.subr

name=resin2
rcvar=`set_rcvar`

command="/usr/local/sbin/resin2ctl"
command_args="start"
pidfile=/usr/local/resin2/resin2.pid

# set defaults

resin2_enable=${resin2_enable:-"NO"}
resin2_user=${resin2_user:-"www"}
resin2_group=${resin2_group:-"www"}

load_rc_config ${name}

if test -n "${resin2_java_version}" ; then
    JAVA_HOME=$(JAVA_VERSION="${resin2_java_version}" JAVAVM_DRYRUN=1 /usr/local/bin/java | grep JAVA_HOME | cut -d= -f2)
    procname=$(JAVA_VERSION="${resin2_java_version}" JAVAVM_DRYRUN=1 /usr/local/bin/java | grep JAVAVM_PROG | cut -d= -f2)
else
    JAVA_HOME=$(JAVAVM_DRYRUN=1 /usr/local/bin/java | grep JAVA_HOME | cut -d= -f2)
    procname=$(JAVAVM_DRYRUN=1 /usr/local/bin/java | grep JAVAVM_PROG | cut -d= -f2)
fi

export JAVA_HOME

run_rc_command "$1"
