#!/bin/sh

# PROVIDE: rslsync
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# rslsync_enable (bool):        Set to NO by default.
#                               Set it to YES to enable it.
# rslsync_user:        	        The user account rslsync daemon runs as
#                               what you want it to be. It uses '%%USER%%'
#                               user by default. Do not sets it as empty or it
#                               will run as root.
# rslsync_group:                The group account rslsync daemon runs as
#                               what you want it to be. It uses '%%GROUP%%'
#                               group by default. Do not sets it as empty or it
#                               will run as wheel.

. /etc/rc.subr
name="rslsync"
rcvar="${name}_enable"
load_rc_config ${name}

: ${rslsync_enable:="NO"}
: ${rslsync_user:="%%USER%%"}
: ${rslsync_group:="%%GROUP%%"}

pidfile="/var/run/rslsync/rslsync.pid"
command="%%PREFIX%%/bin/rslsync"
command_args="--config %%PREFIX%%/etc/rslsync.conf"

start_precmd=rslsync_prestart
rslsync_prestart() {
	if [ ! -d ${pidfile%/*} ]; then
		install -d -o ${rslsync_user} -g ${rslsync_group} ${pidfile%/*}
	fi
}

run_rc_command "$1"
