#!/bin/sh /etc/rc.common

START=95
STOP=10
USE_PROCD=1
PROCD_TERM_TIMEOUT=40

PROGRAM=/opt/vocat/bin/vocat
ENV_FILE=/etc/vocat/env

start_service() {
	procd_open_instance
	procd_set_param command "$PROGRAM" serve
	procd_set_param env VOCAT_DATABASE_PATH=/opt/vocat/data/vocat.db
	if [ -r "$ENV_FILE" ]; then
		while IFS='=' read -r name value; do
			case "$name" in
				VOCAT_*) procd_append_param env "$name=$value" ;;
			esac
		done < "$ENV_FILE"
	fi
	procd_set_param respawn 3600 5 5
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_close_instance
}

service_triggers() {
	procd_add_reload_trigger vocat
}
