#!/bin/sh

# PROVIDE: %%PORTNAME%%
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# go_cve_dictionary_enable (bool):     Set to NO by default
#                                      Set it to YES to enable the CVE server
# go_cve_dictionary_user (string):     Set user to run go_cve_dictionary
#                                      Default is "%%USERS%%"
# go_cve_dictionary_group (string):    Set group to run go_cve_dictionary
#                                      Default is "%%GROUPS%%"
# go_cve_dictionary_log_file (string): Set file that go-cve-dictionary will log to
#                                      Default is "/var/log/vuls/go_cve_dictionary.log"
# go_cve_dictionary_args (string):     Set additional command line arguments
#                                      Default is ""
#
# Set up go-cve-dictionary using the config file: %%PREFIX%%/etc/go-cve-dictionary.yaml
#

. /etc/rc.subr

name=go_cve_dictionary
rcvar=go_cve_dictionary_enable

load_rc_config $name

: ${go_cve_dictionary_enable:="NO"}
: ${go_cve_dictionary_user:="%%USERS%%"}
: ${go_cve_dictionary_group:="%%GROUPS%%"}
: ${go_cve_dictionary_log_file:="/var/log/vuls/go_cve_dictionary.log"}
: ${go_cve_dictionary_args:=""}

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

command_args="-p ${pidfile} -P ${pidfile_daemon} -t ${name} \
	-Ho ${go_cve_dictionary_log_file} \
	${procname} server \
	${go_cve_dictionary_args}"

start_precmd=go_cve_dictionary_startprecmd

go_cve_dictionary_startprecmd()
{
	/usr/bin/install -o ${go_cve_dictionary_user} -g ${go_cve_dictionary_group} \
		-m 640 /dev/null ${pidfile}
	/usr/bin/install -o ${go_cve_dictionary_user} -g ${go_cve_dictionary_group} \
		-m 640 /dev/null ${pidfile_daemon}
}

load_rc_config $name
run_rc_command "$1"
