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

USE_PROCD=1
START=99

CONF="gost"
PROG="/usr/bin/gost"

start_service() {
	local enabled

	config_load "gost"
	config_get_bool enabled "config" "enabled" 0
	[ "$enabled" -eq 1 ] || return 1

	local config_file arguments
	config_get config_file "config" "config_file"
	config_get arguments "config" "arguments"

	procd_open_instance

	procd_set_param command "$PROG"
	if [ -n "$config_file" ]; then
		procd_append_param command -C "$config_file"
		procd_set_param file "$config_file"
	fi
	if [ -n "$arguments" ]; then
		set -- $arguments
		procd_append_param command "$@"
	fi

	procd_set_param user gost
	procd_set_param group gost

	procd_set_param limits core="unlimited"
	procd_set_param limits nofile="1000000 1000000"
	procd_set_param stderr 1

	procd_set_param respawn

	procd_close_instance
}

service_triggers() {
	procd_add_reload_trigger "$CONF"
}
