#!/bin/sh /etc/rc.common
# Author: Johannes Pohl <johannes.pohl@badaix.de>
# Co-Author: Szabolcs Hubai <szab.hu@gmail.com>
START=90

USE_PROCD=1

NAME=snapclient
PROG=/usr/bin/$NAME
PID_FILE=/var/run/$NAME.pid

start_service()
{
	config_load "$NAME"

	local enabled
	config_get_bool enabled "config" enabled 0
	[ "$enabled" -ne "1" ] && logger -t $NAME "Disabled in /etc/config/$NAME" && return 1

	local log_sink opts
	config_get log_sink "config" log_sink system
	config_get opts "config" opts ""

	procd_open_instance
	procd_set_param command $PROG
	procd_append_param command --logsink $log_sink
	procd_append_param command $opts
	procd_set_param pidfile $PID_FILE
	procd_set_param respawn # use the defaults for respawing crashed process
	procd_set_param stderr 1
	procd_set_param stdout 1
	procd_close_instance
}
