#!/bin/sh

# PROVIDE: vuls
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# vuls_enable (bool):     Set to NO by default
#                         Set it to YES to enable the vuls server
# vuls_user (string):     Set user to run vuls
#                         Default is "vuls"
# vuls_group (string):    Set group to run vuls
#                         Default is "vuls"
# vuls_log_file (string): Set file that vuls will log to
#                         Default is "/var/log/vuls/vuls.log"
# vuls_args (string):     Set additional command line arguments
#                         Default is ""
#
# Set up vuls using the config file: /usr/local/etc/vuls/config.toml
#

. /etc/rc.subr

name=vuls
rcvar=vuls_enable

load_rc_config $name

: ${vuls_enable:="NO"}
: ${vuls_user:="vuls"}
: ${vuls_group:="vuls"}
: ${vuls_log_file:="/var/log/vuls/vuls.log"}
: ${vuls_results_dir:="/var/db/vuls/results"}
: ${vuls_listen:="0.0.0.0:5515"}
: ${vuls_args:=""}

pidfile=/var/run/${name}.pid
pidfile_daemon=/var/run/${name}_daemon.pid
command="/usr/sbin/daemon"
procname="/usr/local/bin/vuls"

command_args="-p ${pidfile} -P ${pidfile_daemon} -t ${name} -Ho ${vuls_log_file} \
	${procname} server -results-dir=${vuls_results_dir} -to-localfile -listen=${vuls_listen} ${vuls_args}"

start_precmd=vuls_startprecmd

vuls_startprecmd()
{
	/usr/bin/install -o ${vuls_user} -g ${vuls_group} -m 640 /dev/null ${pidfile}
	/usr/bin/install -o ${vuls_user} -g ${vuls_group} -m 640 /dev/null ${pidfile_daemon}
}

load_rc_config $name
run_rc_command "$1"
