#!/bin/sh

# PROVIDE: go-cve-dictionary
# 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 "vuls"
# go_cve_dictionary_group (string):    Set group to run go_cve_dictionary
#                                Default is "vuls"
# go_cve_dictionary_db_path (string):  Set database path
#                                Default is "/var/db/vuls/cve.sqlite3"
# go_cve_dictionary_db_type (string):  Set database type
#                                Default is "sqlite3"
# 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 ""

. /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:="vuls"}
: ${go_cve_dictionary_group:="vuls"}
: ${go_cve_dictionary_db_path:="/var/db/vuls/cve.sqlite3"}
: ${go_cve_dictionary_db_type:="sqlite3"}
: ${go_cve_dictionary_log_file:="/var/log/vuls/go_cve_dictionary.log"}
: ${go_cve_dictionary_args:=""}

pidfile=/var/run/go_cve_dictionary.pid
command="/usr/sbin/daemon"
procname="/usr/local/bin/go-cve-dictionary"

command_args="-p ${pidfile} /usr/bin/env ${procname} server \
                -dbpath=${go_cve_dictionary_db_path} \
                -dbtype=${go_cve_dictionary_db_type} \
                ${go_cve_dictionary_args} >> ${go_cve_dictionary_log_file} 2>&1"

start_precmd=go_cve_dictionary_startprecmd

go_cve_dictionary_startprecmd()
{
    if [ ! -e ${pidfile} ]; then
        install -o ${go_cve_dictionary_user} -g ${go_cve_dictionary_group} \
            -m 640 /dev/null ${pidfile};
    fi
    if [ ! -f "${go_cve_dictionary_log_file}" ]; then
        install -o ${go_cve_dictionary_user} -g ${go_cve_dictionary_group} \
            -m 640 /dev/null ${go_cve_dictionary_log_file};
    fi
}

load_rc_config $name
run_rc_command "$1"
