#!/bin/sh
#
# $FreeBSD: www/jetty/files/jetty.in 300897 2012-07-14 14:29:18Z beat $
#

# PROVIDE: jetty
# REQUIRE: LOGIN
# KEYWORD: shutdown

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

. /etc/rc.subr

name=jetty
rcvar=jetty_enable

command="/usr/local/sbin/jettyctl"
command_args="start"
pidfile=/usr/local/jetty/jetty.pid

# set defaults

jetty_enable=${jetty_enable:-"NO"}
jetty_user=${jetty_user:-"www"}
jetty_group=${jetty_group:-"www"}

load_rc_config ${name}

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