#!/bin/sh
#
# $FreeBSD: ports/textproc/pootle/files/pootle.sh.in,v 1.6 2012/01/14 08:57:09 dougb Exp $
#
# PROVIDE: pootle
# REQUIRE: DAEMON
#
# Add the following lines to /etc/rc.conf to run pootle:
#
# pootle_enable (bool):		Set it to "YES" to enable pootle.
#				Default is "NO".
# pootle_flags (flags):		Set extra flags here. More options in pootle(1)
#				Default is empty "".
# pootle_logdir (path):		Path to pootle log directory.
#				Default is "/var/log/pootle".
#				Empty is log to /dev/null.
# pootle_user (user):		Set user to run pootle.
#				Default is "nobody".
#

. /etc/rc.subr

name=pootle
rcvar=pootle_enable
pidfile="/var/run/pootle/pootle.pid"
command_interpreter="/usr/local/bin/python2.7"

required_files="/usr/local/etc/pootle/localsettings.py"

command="/usr/local/bin/PootleServer"

load_rc_config $name
: ${pootle_enable="NO"}
: ${pootle_user="nobody"}
: ${pootle_logdir="/var/log/pootle"}

if [ -n "${pootle_logdir}" ]; then
	pootle_stdout="${pootle_logdir}/access.log"
	pootle_stderr="${pootle_logdir}/error.log"
else
	pootle_stdout="/dev/null"
	pootle_stderr="/dev/null"
fi

start_cmd="pootle_start_cmd"

pootle_start_cmd () {
	[ -z "${rc_quiet}" ] && echo "Starting ${name}."
	/usr/sbin/daemon -p ${pidfile} -u ${pootle_user} ${command} ${pootle_flags} \
		>>${pootle_stdout} 2>>${pootle_stderr}
}

run_rc_command "$1"
