#!/bin/sh
#
# $FreeBSD
#

# PROVIDE: bastillion
# REQUIRE: NETWORKING SERVERS
# KEYWORD: shutdown

#
# Add the following line to /etc/rc.conf to enable %%APP_NAME%%:
#
# %%APP_NAME%%_enable="YES"
#

. /etc/rc.subr

name=%%APP_NAME%%
rcvar=%%APP_NAME%%_enable

command="%%PREFIX%%/jetty_%%APP_NAME%%/bin/jetty.sh"
command_args="start"

# set defaults

%%APP_NAME%%_enable=${%%APP_NAME%%_enable:-"NO"}
%%APP_NAME%%_user=${%%APP_NAME%%_user:-"www"}
%%APP_NAME%%_group=${%%APP_NAME%%_group:-"www"}

if [ ! -d /var/run/%%APP_NAME%% ]; then
	mkdir -p /var/run/%%APP_NAME%%
	chown www:www /var/run/%%APP_NAME%%
fi

load_rc_config ${name}

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

export JAVA_HOME

run_rc_command "$1"
