#!/bin/sh
#
# PROVIDE: athens
# REQUIRE: LOGIN NETWORKING
# KEYWORD: shutdown
#
# athens_enable (bool):
#   Default value: "NO"
#   Flag that determines whether athens is enabled
#
# athens_config (string)
#   Default value /usr/local/etc/athens/athens.toml
#   Path to the athens configuration file
#
# athens_user (string)
#   This is the user that athens runs as
#   Set to athens by default
#
# athens_group (string)
#   This is the group that athens runs as
#   Set to athens by default

. /etc/rc.subr

name=athens
rcvar=athens_enable

load_rc_config $name

: ${athens_enable:="NO"}
: ${athens_config:="/usr/local/etc/athens/athens.toml"}
: ${athens_user:=athens}
: ${athens_group:=athens}

athens_command="/usr/local/bin/athens -config_file ${athens_config}"
pidfile="/var/run/${name}/${name}.pid"
command="/usr/sbin/daemon"
command_args="-P ${pidfile} -S ${athens_command}"

PATH="${PATH}:/usr/local/bin"

required_files="${athens_config}"

start_precmd="athens_precmd"

athens_precmd()
{
  /usr/bin/install -d -m 700 -o "${athens_user}" -g "${athens_group}" /var/run/athens
}

run_rc_command "$1"
