#!/bin/sh

# PROVIDE: paperless-consumer
# REQUIRE: LOGIN
# BEFORE:  paperless-flower
# KEYWORD: shutdown
#
# Add the following line(s) to /etc/rc.conf to enable the paperless
# celery consumer process:
#
# paperless_consumer_enable (bool):	Set to "NO" by default.
#					Set it to "YES" to enable
#					paperless_consumer
# paperless_consumer_user (str):	Set to "paperless" by default.
#					User to run consumer.
# paperless_consumer_log_facility(str): Set to "daemon" by default.
#					Consumer logging syslog facility.
# paperless_consumer_log_priority(str): Set to "notice" by default.
#					Consumer logging syslog priority.
# paperless_consumer_log_tag (str):	Set to "paperless-consumer" by default.
#					Consumer logging syslog tag.
# paperless_consumer_tmpdir (str):	If set, overrides TMPDIR

. /etc/rc.subr

name="paperless_consumer"
rcvar="${name}_enable"

# read configuration and set defaults
load_rc_config "$name"
paperless_consumer_enable=${paperless_consumer_enable:-"NO"}
paperless_consumer_daemon_user=${paperless_consumer_user:-"paperless"}
paperless_consumer_log_facility=${paperless_consumer_log_facility:-"daemon"}
paperless_consumer_log_priority=${paperless_consumer_log_priority:-"notice"}
paperless_consumer_log_tag=${paperless_consumer_log_tag:-"paperless-consumer"}
paperless_consumer_tmpdir=${paperless_consumer_tmpdir:-"$TMPDIR"}

paperless_consumer_env="LANG=en_US.UTF-8 PATH=$PATH:%%PREFIX%%/bin\
  PYTHONPATH=%%PYTHONPREFIX_SITELIBDIR%%/paperless"

if [ -n "$paperless_consumer_tmpdir" ]; then
	paperless_consumer_env="$paperless_consumer_env TMPDIR=\
$paperless_consumer_tmpdir"
fi

sig_stop="INT"
pidfile="/var/run/paperless/consumer.pid"
procname="%%PYTHON_CMD%%"
command="/usr/sbin/daemon"
command_args="-cS -u ${paperless_consumer_daemon_user} \
	-p ${pidfile} \
	-t paperless-consumer \
	-l ${paperless_consumer_log_facility} \
	-s ${paperless_consumer_log_priority} \
	-T ${paperless_consumer_log_tag} \
	%%PREFIX%%/bin/paperless document_consumer"

run_rc_command "$1"
