#!/ffp/bin/sh

# PROVIDE: gerbera

. /ffp/etc/ffp.subr

name="gerbera"
command="/ffp/bin/$name"
home_dir="/ffp/share/gerbera"
pid_dir="/ffp/var/run/$name/"
iface="egiga0"
log_file="/ffp/var/log/gerbera.log"
required_files="$command"
runas_user="$user"
gerbera_args="-e $iface -m $home_dir"
if	[ -n "$gerbera_args" ]
then
	command="$command $gerbera_args"
fi

start_cmd="gerbera_start"
stop_cmd="gerbera_stop"
status_cmd="gerbera_status"

add_user()
{
	/ffp/bin/id -g "$runas_user" &>/dev/null || /ffp/sbin/groupadd -r "$runas_user" >/dev/null
	/ffp/bin/id -u "$runas_user" &>/dev/null || /ffp/sbin/useradd -r -g "$runas_user" -d "$home_dir" -s /ffp/bin/false -c gerbera "$runas_user" >/dev/null
}

check_status()
{
	status=$(pgrep -f "$command")
	retvalue=$?
}

gerbera_start()
{
	check_status
	echo "Starting $name..."
	$command>$log_file 2>&1 </dev/null &
}

gerbera_stop()
{
	check_status
	if	[ "$retvalue" = "0" ]
	then
	echo "Stopping $name..."
	pkill -fP1 "$command"
	sleep 2
	killall $name > /dev/null 2>&1
	else
	echo "$name isn't running..."
	fi
}

gerbera_status()
{
	check_status
	if	[ "$retvalue" = "0" ]
	then
		echo "$name is running with process ID(s):"${status[*]}""
	else
	echo "$name isn't running..."
	fi
}

run_rc_command "$1"

