#!/bin/sh

# PROVIDE: fluentd
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# fluentd_enable (bool):	Set to NO by default.
# 		  		Set it to YES to enable fluentd.
# fluentd_config (path):	Set to %%PREFIX%%/etc/fluentd/fluent.conf
# 		  		by default.
# fluentd_flags (str):          Set to "" by default.

. /etc/rc.subr

name=fluentd
rcvar=fluentd_enable
extra_commands="init"

load_rc_config $name

: ${fluentd_enable:="NO"}
: ${fluentd_config="%%PREFIX%%/etc/fluentd/fluent.conf"}
: ${fluentd_dir="%%PREFIX%%/etc/fluentd"}
: ${fluentd_user="%%USER%%"}
: ${fluentd_group="%%GROUP%%"}
: ${fluentd_flags:=""}

start_precmd="fluentd_start_precmd"

command=%%PREFIX%%/bin/${name}
pidfile=/var/run/${name}/${name}.pid
command_interpreter=%%RUBY%%

command_args="-d $pidfile -c $fluentd_config"

fluentd_start_precmd()
{
    install -d -o ${fluentd_user} -g ${fluentd_group} -m 775 ${fluentd_dir}
    install -d -o ${fluentd_user} -g ${fluentd_group} -m 775 /var/run/fluentd
}

run_rc_command "$1"
