#!/bin/sh

# PROVIDE: garage
# REQUIRE: NETWORKING
# KEYWORD: shutdown

# Configuration settings for Garage in /etc/rc.conf
#
# garage_enable (bool):     Enable Garage. (default=NO)
# garage_config (str):      Garage configuration file. (default=/usr/local/etc/garage.toml)
# garage_log_file (str):    Log output. May be set to syslog. (default=/var/log/garage.log)
# garage_runas (str):       User to run Garage as. (default=garage)
#

. /etc/rc.subr

name=garage
desc="Distributed object storage"
rcvar=${name}_enable

# read configuration and set defaults
load_rc_config $name
: ${garage_enable="NO"}
: ${garage_config="/usr/local/etc/garage.toml"}
: ${garage_log_file="/var/log/garage.log"}
: ${garage_runas:="garage"}

command=/usr/sbin/daemon
procname="/usr/local/bin/${name}"
required_files="${garage_config}"
pidfile="/var/run/${name}.pid"
command_args=

if [ "${garage_log_file}" = syslog ]; then
	garage_env="${garage_env} GARAGE_LOG_TO_SYSLOG=1"
else
	command_args="-H -o ${garage_log_file}"
fi

command_args="${command_args} -f -u ${garage_runas} -p ${pidfile} ${procname} -c ${garage_config} server"

status_cmd="${procname} -c ${garage_config} status"

run_rc_command "$1"
