#!/bin/sh
#
# $FreeBSD: ports/www/resin3/files/resin3.in,v 1.3 2012/10/17 21:34:35 jgh Exp $
#

# PROVIDE: resin3
# REQUIRE: LOGIN NETWORKING SERVERS
# KEYWORD: shutdown

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


resin3_enable="${resin3_enable:-"NO"}"
resin3_user="${resin3_user:-"www"}"
resin3_group="${resin3_group:-"www"}"

. /etc/rc.subr

name="resin3"
rcvar="resin3"_enable

load_rc_config ${name}

command="/usr/local/sbin/resin3ctl"
command_args="start"
pidfile="/usr/local/resin3/resin3.pid"

if test -n "${resin3_java_version}" ; then
    JAVA_HOME=$(JAVA_VERSION="${resin3_java_version}" JAVAVM_DRYRUN=1 /usr/local/bin/java | grep JAVA_HOME | cut -d= -f2)
    procname=$(JAVA_VERSION="${resin3_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"
