#!/bin/sh

# PROVIDE: geoserver
# REQUIRE: NETWORKING
#
# Add the following line to /etc/rc.conf[.local] to enable geoserver
#
# geoserver_enable (bool):	Set to "NO" by default.
#				Set it to "YES" to enable geoserver.


. /etc/rc.subr

name="geoserver"
rcvar=geoserver_enable

load_rc_config ${name}

: ${geoserver_enable="NO"}
: ${geoserver_stdout_log="/var/log/geoserver_output.log"}
: ${geoserver_stderr_log="/var/log/geoserver_error.log"}
: ${geoserver_user="root"}
: ${geoserver_chdir="%%GEOSERVERDIR%%"}
: ${geoserver_pidfile="/var/run/geoserver.pid"}

java_args="-DGEOSERVER_DATA_DIR=%%GEOSERVERDIR%%/data_dir -Djava.awt.headless=true \
		-DSTOP.PORT=8079 -DSTOP.KEY=geoserver -jar start.jar"
log_args=">> ${geoserver_stdout_log} 2>> ${geoserver_stderr_log}"

pidfile=${geoserver_pidfile}
command="/usr/sbin/daemon"
command_args="-p ${pidfile} %%JAVA%% ${java_args} ${geoserver_flags} ${log_args}"
procname="%%JAVA%%"

start_precmd=logs_touch

logs_touch()
{
    touch $geoserver_stdout_log $geoserver_stderr_log
    chown $geoserver_user $geoserver_stdout_log $geoserver_stderr_log
}

run_rc_command "$1"
